Pysimplegui 2020 Clearly Seeing A Gui For You: The Basic Questions: Who
Pysimplegui 2020 Clearly Seeing A Gui For You: The Basic Questions: Who
Message
User Read request
Code
Reads Message
Queue
Message
Read a Queue
(Pull Model)
Segmented Code
Into Callback
Functions Button Click Event
Button 3
Code
Button Click
Input
Button click
Changed
Callback
Callback
Event Loop
If event == Button ’
If event == Button ’
If event == Slider
If event == Input
GitHub
• http://www.PySimpleGUI.com
• Latest code – Each port in a different folder with a readme
• Issues – Please use the Issue Form
• Demos – Universal folder and per-port folders
• import PySimpleGUI as sg
• Name your Window window
• Read your window into variables event and values
• Name your layout layout
• Use window[key] to lookup elements
• For keys that are strings, follow the pattern '-KEY-'
• Congratulations, it’s time you learn how to make your own windows
Input popups
“One Shot” programs lack “Event Loops” and can be 1 line of code.
# 1 - The import
import PySimpleGUI as sg
# 2 - Layout definition
layout = [[sg.Text('My layout')],
[sg.Input(key='-INPUT-')],
[sg.Button('OK'), sg.Button('Cancel')] ]
# 3 - Create window
window = sg.Window('Design Pattern 3 - Persistent Window', layout)
# 4 - Event Loop
while True:
event, values = window.read()
if event in (None, 'Cancel'):
break
# 5 - Close window
window.close()
# 2 - Layout definition
layout = [[sg.Text('My layout')],
[sg.Input(key='-INPUT-')],
[sg.Button('OK'), sg.Button('Cancel')] ]
o Frame
o Tab, TabGroup
o Pane
sg.Window('Sudoku',[[sg.Frame('',[[sg.I(random.randint(1,9), justification='r',
size=(3,1),key=(frow*3+row,fcol*3+col)) for col in range(3)] for row in range(3)]) for
fcol in range(3)] for frow in range(3)]+ [[sg.B('Exit')]]).read()