Pysimplegui 简明教程

PySimpleGUI - Element Class

PySimpleGUI 库包含许多 GUI 小组件,可将其放置在窗口对象之上。例如,我们在上述示例中使用的按钮或文本框。所有这些小组件实际上都是此库中定义的类的对象,其中 Element 类充当所有其他小组件类的基础。

The PySimpleGUI library consists of a number of GUI widgets that can be placed on top of the Window object. For instance, the buttons or the textboxes that we have used in the above examples. All these widgets are in fact objects of classes defined in this library, in which Element class acts as the base for all other widget classes.

这种 Element 类对象永远不会显式声明。它定义了诸如大小、颜色等通用属性。以下是可用小组件(也称为元素)的列表

An object of this Element class is never declared explicitly. It defines the common properties like size, color, etc. Here is the list of the available widgets (also called elements)

Sr.No.

Widget & Description

1

Text ElementDisplay some text in the window. Usually this means a single line of text.

2

Input ElementDisplay a single text input field.

3

*Multiline Element*Display and/or read multiple lines of text. This is both an input and output element.

4

Combo ElementA combination of a single-line input and a drop-down menu.

5

*OptionMenu Element*Similar to Combo. Only on TKinter port

6

Checkbox ElementDisplays a checkbox and text next to it.

7

Radio ElementUsed in a group of other Radio Elements to provide user with ability to select only one choice in a list of choices.

8

Spin ElementA spinner with up/down buttons and a single line of text.

9

*Button Element*Defines all possible buttons. The shortcuts such as Submit, FileBrowse, …​ each create a Button

10

*ButtonMenu element *Creates a button that when clicked will show a menu similar to right click menu.

11

Slider ElementHorizontal or vertical slider to increment/decrement a value.

12

Listbox ElementProvide a list of values for the user to choose one or more of. Returns a list of selected rows when a window.read() is executed.

13

Image ElementShow an image in the window. Should be a GIF or a PNG only.

14

Graph ElementCreates area to draw graph

15

Canvas ElementAn area to draw shapes

16

ProgressBar ElementDisplays a colored bar that is shaded as progress of some operation is made.

17

Table ElementDisplay data in rows and columns

18

Tree ElementPresents data in a tree-like manner, much like a file/folder browser.

19

*Sizer Element*This element is used to add more space.

20

*StatusBar Element*A StatusBar Element creates the sunken text-filled strip at the bottom.

21

Frame ElementThe Frame element is a container object that holds on or more elements of other types.

22

Column ElementIt is very useful if you want to design the GUI window elements represented in one or more vertical columns.

23

Tab ElementThe use of Tab elements makes the design very convenient, effective and easy for the user to navigate. Tab element is also a container element such as Frame or Column.

Properties of Element Class

以下是元素类的属性 −

Following are the properties of the Element Class −

Sr.No.

Property & Description

1

size(w=characters-wide, h=rows-high)

2

*font*specifies the font family, size

3

*background_color*color of background

4

*text_color*element’s text color

5

*key*Identifies an Element

6

*visible*set visibility state of the element (Default = True)

Methods of Element Class

以下是元素类的方法 −

Following are the methods of the Element Class −

Sr.No.

Method & Description

1

*set_tooltip()*Called by application to change the tooltip text for an Element

2

*set_focus()*Sets the current focus to be on this element

3

*set_size()*Changes the size of an element to a specific size

4

*get_size()*Return the size of an element in Pixels

5

*expand()*Causes the Element to expand to fill available space in the X and Y directions

6

*set_cursor()*Sets the cursor for the current Element

7

*set_right_click_menu()*Sets right click menu to be invoked when clicked