整理 PySimpleGUI 官方网站
原文google翻译过来的
https://pysimplegui.readthedocs.io/en/latest/
您将找到有关Elements的信息,所有其他类和函数都位于本手册结尾处。它们位于自述文件的大部分中,按字母顺序排列以便于查找。本节对Elements的讨论旨在教您如何工作。另一部分包含详细的呼叫签名和参数定义。
图像元素 Image Element
Image Element - show an image in the window. Should be a GIF or a PNG only
Image(filename=None,
data=None,
background_color=None,
size=(None, None),
pad=None,
key=None,
tooltip=None,
right_click_menu=None,
visible=True,
enable_events=False,
metadata=None)
参数说明:
参数类型 | 参数名 | 说明 | ||
---|---|---|---|---|
str | 力量 | str | 文件名 | 图像文件名(如果有按钮图像)。仅GIF和PNG。 |
Union[bytes, str] | 联合[字节,str] | Union[bytes, str] | 数据 | 要放入按钮的图像的原始或Base64表示形式。选择文件名或数据 |
0 | 0 | 0 | 背景颜色 | 背景色 |
Tuple[int, int] | 元组[int,int] | Tuple[int, int] | 尺寸 | (宽度,高度)图像尺寸(以像素为单位) |
(int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | (int,int)或((int,int),(int,int))或(int,(int,int))或((int,int),int) | (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | 垫 | 元素(左/右,上/下)或((左,右),(上,下))周围的填充量 |
Any | 任何 | Any | 键 | 与window.FindElement和返回值一起使用,以唯一标识此元素,以唯一标识此元素 |
str | 力量 | str | 工具提示 | 鼠标悬停在元素上时显示的文本 |
List[List[Union[List[str],str]]] | List [List [Union [List [str],str]]] | List[List[Union[List[str],str]]] | right_click_menu | 右键单击此元素时显示的菜单项列表的列表。有关详细格式,请参见用户文档。 |
bool | 布尔 | bool | 可见 | 设置元素的可见性状态 |
bool | 布尔 | bool | enable_events | 打开特定于元素的事件。对于图片元素,事件为“点击图片” |
Any | 任何 | Any | 元数据 | 可以设置为任何内容的用户元数据 |
设定焦点
将当前焦点设置在此元素上
SetFocus(force=False)
参数说明:
参数类型 | 参数名 | 说明 |
---|---|---|
布尔 | 力 | 如果为True,则将调用focus_force;否则,将调用focus_set |
bool | force | if True will call focus_force otherwise calls focus_set |
设定工具提示
由应用程序调用以更改元素的工具提示文本。通常使用Element Object调用,例如:window.Element(‘key’)。SetToolTip(‘New tip’)。
SetTooltip(tooltip_text)
参数说明:
参数类型 | 参数名 | 说明 |
---|---|---|
力量 | tooltip_text | 要在工具提示中显示的文本。 |
str | tooltip_text | the text to show in tooltip. |
更新资料
更改图像元素的某些设置。必须致电Window.Read或Window.Finalize事先
Update(filename=None,
data=None,
size=(None, None),
visible=None)
参数说明:
参数类型 | 参数名 | 说明 | ||
---|---|---|---|---|
str | 力量 | str | 文件名 | 文件名到要显示的新图像。 |
Union[str, tkPhotoImage] | 联合[str,tkPhotoImage] | Union[str, tkPhotoImage] | 数据 | Base64编码的字符串或tk.PhotoImage对象 |
Tuple[int,int] | 元组[int,int] | Tuple[int,int] | 尺寸 | 图片大小(w,h)w =字符宽,h =行高 |
bool | 布尔 | bool | 可见 | 控制元素的可见性 |
UpdateAnimation
显示动画GIF。您可以随时调用该函数。该功能将确定何时显示下一帧,并在合适的时间自动前进到下一帧。注意-不执行睡眠呼叫以延迟
UpdateAnimation(source, time_between_frames=0)
参数说明:
参数类型 | 参数名 | 说明 | ||
---|---|---|---|---|
Union[str,bytes] | 联合[str,bytes] | Union[str,bytes] | 资源 | 包含动画GIF的文件名或Base64编码的字符串 |
int | 整型 | int | time_between_frames | 显示帧之间要等待的毫秒数 |
捆绑
用于将tkinter事件添加到Element。tkinter特定数据位于Element的成员变量user_bind_event中
bind(bind_string, key_modifier)
扩大
使元素扩展以填充X和Y方向上的可用空间。可以指定哪个或两个方向
expand(expand_x=False,
expand_y=False,
expand_row=True)
get_size
返回像素的大小。必须小心,因为某些元素使用字符来指定其大小,但是在调用此get_size方法时将返回像素。
get_size()
参数类型 | 参数名 | 说明 |
---|---|---|
— | 返回 | 元素的宽度和高度 |
— | return | width and height of the element |
hide_row
隐藏元素所在的整行。如果在隐藏元素(包括行容器)时必须删除所有空间,请使用此选项
hide_row()
更新
更改图像元素的某些设置。必须致电Window.Read或Window.Finalize事先
update(filename=None,
data=None,
size=(None, None),
visible=None)
参数说明:
参数类型 | 参数名 | 说明 | ||
---|---|---|---|---|
str | 力量 | str | 文件名 | 文件名到要显示的新图像。 |
Union[str, tkPhotoImage] | 联合[str,tkPhotoImage] | Union[str, tkPhotoImage] | 数据 | Base64编码的字符串或tk.PhotoImage对象 |
Tuple[int,int] | 元组[int,int] | Tuple[int,int] | 尺寸 | 图片大小(w,h)w =字符宽,h =行高 |
bool | 布尔 | bool | 可见 | 控制元素的可见性 |
update_animation
显示动画GIF。您可以随时调用该函数。该功能将确定何时显示下一帧,并在合适的时间自动前进到下一帧。注意-不执行睡眠呼叫以延迟
update_animation(source, time_between_frames=0)
参数说明:
参数类型 | 参数名 | 说明 | ||
---|---|---|---|---|
Union[str,bytes] | 联合[str,bytes] | Union[str,bytes] | 资源 | 包含动画GIF的文件名或Base64编码的字符串 |
int | 整型 | int | time_between_frames | 显示帧之间要等待的毫秒数 |
update_animation_no_buffering
显示动画GIF。您可以随时调用该函数。该功能将确定何时显示下一帧,并在合适的时间自动前进到下一帧。注意-不执行睡眠呼叫以延迟
update_animation_no_buffering(source, time_between_frames=0)
参数说明:
参数类型 | 参数名 | 说明 | ||
---|---|---|---|---|
Union[str,bytes] | 联合[str,bytes] | Union[str,bytes] | 资源 | 包含动画GIF的文件名或Base64编码的字符串 |
int | 整型 | int | time_between_frames | 显示帧之间要等待的毫秒数 |