美文网首页
PySimpleGUI中常用组件

PySimpleGUI中常用组件

作者: 张小Di | 来源:发表于2020-05-25 15:16 被阅读0次

知己知彼,方能百战不殆。如若想使用PySimpleGUI库来实现GUI布局,那么需要简单的了解其所包含的组件
查看PySimpleGUI.py,其包含以下元素类型:

# -------------------------  Element types  ------------------------- #

ELEM_TYPE_TEXT = 'text'
ELEM_TYPE_INPUT_TEXT = 'input'
ELEM_TYPE_INPUT_COMBO = 'combo'
ELEM_TYPE_INPUT_OPTION_MENU = 'option menu'
ELEM_TYPE_INPUT_RADIO = 'radio'
ELEM_TYPE_INPUT_MULTILINE = 'multiline'
ELEM_TYPE_INPUT_CHECKBOX = 'checkbox'
ELEM_TYPE_INPUT_SPIN = 'spind'
ELEM_TYPE_BUTTON = 'button'
ELEM_TYPE_IMAGE = 'image'
ELEM_TYPE_CANVAS = 'canvas'
ELEM_TYPE_FRAME = 'frame'
ELEM_TYPE_GRAPH = 'graph'
ELEM_TYPE_TAB = 'tab'
ELEM_TYPE_TAB_GROUP = 'tabgroup'
ELEM_TYPE_INPUT_SLIDER = 'slider'
ELEM_TYPE_INPUT_LISTBOX = 'listbox'
ELEM_TYPE_OUTPUT = 'output'
ELEM_TYPE_COLUMN = 'column'
ELEM_TYPE_MENUBAR = 'menubar'
ELEM_TYPE_PROGRESS_BAR = 'progressbar'
ELEM_TYPE_BLANK = 'blank'
ELEM_TYPE_TABLE = 'table'
ELEM_TYPE_TREE = 'tree'
ELEM_TYPE_ERROR = 'error'
ELEM_TYPE_SEPARATOR = 'separator'
ELEM_TYPE_STATUSBAR = 'statusbar'
ELEM_TYPE_PANE = 'pane'
ELEM_TYPE_BUTTONMENU = 'buttonmenu'

其中,常用控件如下:
Text:文本
InputText:输入框
InputCombo:下拉列表框
Multiline:大文本框
Listbox:多行列表文本框
Checkbox:多选框
Radio:单选框
Slider:拖动按钮
FolderBrowse:选取文件夹
FilerBrowse:选取文件
Button:按钮
Quit
Cancel:取消
Menu:菜单
Column:列
Frame:块

源代码,如下:

import PySimpleGUI as sg
#import triangle
  
col=[[sg.Text('col Row 1')],
[sg.Text('col Row 2'),sg.Input('col input 1')],]

layout=[
[sg.Column(col)],
[sg.Text('X:',text_color='blue'),sg.InputText(size=(15,))],
[sg.Text('',key='三角形判断',size=(20,2))],
[sg.Multiline(default_text='default_text',size=(30,6))],
[sg.Checkbox('My first checkbox!',default=True),sg.Checkbox('My second checkbox!')],
[sg.Radio('My first Radio!', "RADIO1", default=True), sg.Radio('My second Radio!', "RADIO1")],
[sg.InputCombo(['Combobox 1','Combobox 2'],size=(20,3))],
[sg.Listbox(values=['Listbox 1','Listbox 2','Listbox 3'],size=(30,6))],
[sg.Text('Source Folder',size=(15,1),auto_size_text=False,justification='left'),sg.InputText('Source'),sg.FolderBrowse()],
[sg.Text('Source Folder',size=(15,1),auto_size_text=False,justification='left'),sg.InputText('Source'),sg.FileBrowse()],
[sg.Slider(range=(1,100),orientation='h',size=(35,20),default_value=85)],
[sg.Slider(range=(1,100),orientation='v',size=(10,20),default_value=25)],
[sg.Button('结果:',key='submit')],
[sg.Cancel('cancel')],
[sg.Quit('exit',key='q')],
]
sg.Print('The first call sets some window settings like font that cannot be changed')
# Create the Window
window=sg.Window('常用控件',layout,font='微软雅黑')
# Create the event loop
while True:
    event,value=window.Read()

window.Close()

结果,如下:

image.png

参考:
PySimpleGUI: 开发自己第一个软件
python-笔记 PySimpleGUI 图形界面-1 各种控件整理
http://www.360doc.com/content/19/0306/17/99071_819661295.shtml

相关文章

网友评论

      本文标题:PySimpleGUI中常用组件

      本文链接:https://www.haomeiwen.com/subject/cyteahtx.html