整理 PySimpleGUI 官方网站
原文google翻译过来的
https://pysimplegui.readthedocs.io/en/latest/
您将找到有关Elements的信息,所有其他类和函数都位于本手册结尾处。它们位于自述文件的大部分中,按字母顺序排列以便于查找。本节对Elements的讨论旨在教您如何工作。另一部分包含详细的呼叫签名和参数定义。
按钮菜单元素ButtonMenu元素
The Button Menu Element. Creates a button that when clicked will show a menu similar to right click menu
ButtonMenu(button_text,
menu_def,
tooltip=None,
disabled=False,
image_filename=None,
image_data=None,
image_size=(None, None),
image_subsample=None,
border_width=None,
size=(None, None),
auto_size_button=None,
button_color=None,
font=None,
pad=None,
key=None,
tearoff=False,
visible=True,
metadata=None)
参数说明:
参数类型 | 参数名 | 说明 | ||
---|---|---|---|---|
str | 力量 | button_text | button_text | 要在按钮上显示的文字 |
List[List[str]] | 列表[列表[str]] | menu_def | menu_def | 单击此元素时显示的菜单项列表的列表。格式请参阅文档,因为所有菜单类型的格式都相同 |
str | 力量 | tooltip | 工具提示 | 鼠标悬停在元素上时显示的文本 |
bool | 布尔 | disabled | 残障人士 | 如果将创建True按钮,则禁用 |
str | 力量 | image_filename | image_filename | 图像文件名(如果有按钮图像)。仅GIF和PNG。 |
Union[bytes, str] | 联合[字节,str] | image_data | image_data | 要放入按钮的图像的原始或Base64表示形式。选择文件名或数据 |
Tuple[int, int] | 元组[int,int] | image_size | 图片尺寸 | 图片大小(以像素为单位)(宽度,高度) |
int | 整型 | image_subsample | image_subsample | 减少图像尺寸。用这个数字除大小。2 = 1 / 2、3 = 1 / 3、4 = 1/4等 |
int | 整型 | border_width | border_width | 按钮周围的边框宽度(以像素为单位) |
Tuple[int, int] | 元组[int,int] | size | 尺寸 | 按钮的(宽度,高度)宽度(以字符为单位,高为行) |
bool | 布尔 | auto_size_button | auto_size_button | 如果为True,则将按钮大小调整为适合文本的大小 |
Tuple[str, str] | 元组[str,str] | button_color | button_color | (文本颜色,背景颜色)按钮。容易记住,如果您在颜色之间说“开”,那是哪个。“红色”上的“绿色” |
Union[str, Tuple[str, int]] | 联合[str,元组[str,int]] | font | 字形 | 指定字体系列,大小等 |
(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) | pad | 垫 | 元素(左/右,上/下)或((左,右),(上,下))周围的填充量 |
Any | 任何 | key | 键 | 与window.FindElement和返回值一起使用,以唯一标识此元素,以唯一标识此元素 |
bool | 布尔 | tearoff | 撕下 | 确定菜单是否应允许将其撕下 |
bool | 布尔 | visible | 可见 | 设置元素的可见性状态 |
Any | 任何 | metadata | 元数据 | 可以设置为任何内容的用户元数据 |
请点击
产生按钮的点击,就像用户单击按钮一样。调用按钮的tkinter调用方法
Click()
设定焦点
将当前焦点设置在此元素上
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. |
更新资料
更改ButtonMenu元素的某些设置。必须致电Window.Read或Window.Finalize事先
Update(menu_definition, visible=None)
参数说明:
参数类型 | 参数名 | 说明 | ||
---|---|---|---|---|
List[List] | 清单[清单] | menu_definition | menu_definition | (新菜单定义(以菜单定义格式) |
bool | 布尔 | visible | 可见 | 控制元素的可见性 |
捆绑
用于将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()
set_cursor
设置当前元素的光标。
set_cursor(cursor)
set_focus
将当前焦点设置在此元素上
set_focus(force=False)
参数说明:
参数类型 | 参数名 | 说明 |
---|---|---|
— | 返回 | 当前显示在按钮上的文本 |
布尔 | 力 | 如果为True,则将调用focus_force;否则,将调用focus_set |
bool | force | if True will call focus_force otherwise calls focus_set |
set_size
将元素的大小更改为特定大小。可以为其中一种尺寸指定“无”,以便仅更改元素尺寸之一。
set_size(size=(None, None))
参数说明:
参数类型 | 参数名 | 说明 |
---|---|---|
元组[int,int] | 尺寸 | 字符大小,通常为行。在某些情况下,它们是像素 |
Tuple[int, int] | size | The size in characters, rows typically. In some cases they are pixels |
set_tooltip
由应用程序调用以更改元素的工具提示文本。通常使用Element Object调用,例如:window.Element(‘key’)。SetToolTip(‘New tip’)。
set_tooltip(tooltip_text)
参数说明:
参数类型 | 参数名 | 说明 |
---|---|---|
力量 | tooltip_text | 要在工具提示中显示的文本。 |
str | tooltip_text | the text to show in tooltip. |
解除绑定
从Element中移除先前绑定的tkinter事件。
unbind(bind_string)
unhide_row
取消隐藏(再次显示)Element所在的行容器。请注意,它很可能会重新出现在窗口/容器的底部。
unhide_row()
更新
更改ButtonMenu元素的某些设置。必须致电Window.Read或Window.Finalize事先
update(menu_definition, visible=None)
参数说明:
参数类型 | 参数名 | 说明 | ||
---|---|---|---|---|
List[List] | 清单[清单] | menu_definition | menu_definition | (新菜单定义(以菜单定义格式) |
bool | 布尔 | visible | 可见 | 控制元素的可见性 |