直接pip安装即可。官网还在维护。跨平台+代码简单,不考虑美化的话直接找例子复制即可。
缺点是丑。。我真的觉得不好看。。如果只是想要个简单的图形界面(比方说你原本在用tkinter),那就用这个好了~
文档参考github上的lesson.pdf,还有https://pysimplegui.readthedocs.io/en/latest/cookbook/。资料不少,放心用!
之后我用它写项目了再回来更新!!!
# 窗口title和label都是这个str
# 带浏览按钮
filename = sg.popup_get_file('enter:')
# 这个filename自动换到下一行了.None会写None
sg.popup("you entered", filename)
# 设置主题
sg.theme('Dark Red')
# 按行。一个list object就是一行
layout = [[sg.Text('Browse to a file')],
# visible=False就是不带地址那个输入框
[sg.Input(key='-FILE-', visible=False, enable_events=True),
sg.FileBrowse()]]
event, values = sg.Window('File Compare', layout).read(close=True)
print(f'You chose: {values["-FILE-"]}')
layout = [[sg.Text("What's your name?")],
[sg.Input(key='-INPUT-')],
[sg.Text(size=(40,1), key='-OUTPUT-')], # size是宽高
[sg.Button('Ok'), sg.Button('Quit')]]
# Create the window
window = sg.Window('Window Title', layout)
# Display and interact with the Window using an Event Loop
while True:
event, values = window.read()
# See if user wants to quit or window was closed
if event == sg.WINDOW_CLOSED or event == 'Quit':
break
# Output a message to the window
window['-OUTPUT-'].update('Hello ' + values['-INPUT-'] + "! Thanks for trying PySimpleGUI")
# Finish up by removing from the screen
window.close()
sg.theme("Topanga")
layout = [
[sg.Text("请输入名字、地址和电话号码:")],
[sg.Text("姓名", size=(15, 1)), sg.InputText()],
[sg.Text("地址", size=(15, 1)), sg.InputText()],
[sg.Text("电话", size=(15, 1)), sg.InputText()],
[sg.Submit(), sg.Cancel()]
]
window = sg.Window('标题', layout)
event, values = window.read()
window.close()
print(event) # 输出 Submit / Cancel
print(values) # 按idnex输出dict {0: '名字', 1: '地址', 2: '电话'}
layout = [
[sg.Combo(
['选项一', '选项二', '选项三', '选项四'],
default_value='选项一',
size=(10, 1))],
[sg.OK(), sg.Cancel()] # cancel就会关闭窗口了
]
window = sg.Window('下拉列表元素', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Exit' or event == 'Cancel':
break
print(event, values)
window.close()