整理 PySimpleGUI 官方网站
原文google翻译过来的

https://pysimplegui.readthedocs.io/en/latest/ 您将找到有关Elements的信息,所有其他类和函数都位于本手册结尾处。它们位于自述文件的大部分中,按字母顺序排列以便于查找。本节对Elements的讨论旨在教您如何工作。另一部分包含详细的呼叫签名和参数定义。

菜单元素 Menu Element

菜单元素是提供菜单栏的元素,该菜单栏跨过窗口顶部,标题栏正下方。
这是一个示例布局。 “&”是快捷键ALT +键。
是-“项目字符串” +列表的列表
其中项目字符串是菜单栏本身将显示的内容。
该项目后面的列表表示所显示的项目,然后单击菜单项
请注意,菜单中的“条目”如何成为列表,这意味着它会分支并显示另一个菜单等。(递归)

menu_def = [['&File', ['!&Open', '&Save::savekey', '---', '&Properties', 'E&xit']],
            ['!&Edit', ['!&Paste', ['Special', 'Normal', ], 'Undo'], ],
            ['&Debugger', ['Popout', 'Launch Debugger']],
            ['&Toolbar', ['Command &1', 'Command &2', 'Command &3', 'Command &4']],
            ['&Help', '&About...'], ]

最后,可以将“键”添加到条目中,以使它们唯一。 “保存”条目具有与之关联的密钥。 您
可以看到它有一个“ ::”,它表示密钥的开头。 当用户选择
显示菜单。 密钥部分作为事件的一部分返回。

Menu(menu_definition,
    background_color=None,
    size=(None, None),
    tearoff=False,
    font=None,
    pad=None,
    key=None,
    visible=True,
    metadata=None)

参数说明:

参数类型

参数名

说明

List[List[Tuple[str, List[str]]]

列表[列表[元组[str,列表[str]]]

List[List[Tuple[str, List[str]]]

menu_definition

???

str

力量

str

背景颜色

背景颜色

Tuple[int, int]

元组[int,int]

Tuple[int, int]

尺寸

未在tkinter端口中使用

bool

布尔

bool

撕下

如果为True,则可以将菜单从窗口中撕下并用作浮动窗口。很酷的效果

(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


从所有其他元素中唯一标识此元素的值。查找元素或返回值时使用。窗口必须是唯一的

bool

布尔

bool

可见

设置元素的可见性状态

Any

任何

Any

元数据

可以设置为任何内容的用户元数据

python如何获取element的内容 python elements_参数类型

设定焦点

将当前焦点设置在此元素上

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.

更新资料

更新菜单栏-可以更改菜单定义和可见性。必须指定整个菜单

Update(menu_definition=None, visible=None)

参数说明:

参数类型

参数名

说明

List[List[Tuple[str, List[str]]]

列表[列表[元组[str,列表[str]]]

List[List[Tuple[str, List[str]]]

bool

布尔

bool

python如何获取element的内容 python elements_参数类型_02

捆绑

用于将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()

更新

更新菜单栏-可以更改菜单定义和可见性。必须指定整个菜单

update(menu_definition=None, visible=None)

参数说明:

参数类型

参数名

说明

List[List[Tuple[str, List[str]]]

列表[列表[元组[str,列表[str]]]

List[List[Tuple[str, List[str]]]

bool

布尔

bool

python如何获取element的内容 python elements_参数类型_02