Added a function around the functional example

This commit is contained in:
PySimpleGUI 2023-05-29 10:21:17 -04:00
parent b62648aa23
commit eeb95398e0
1 changed files with 14 additions and 12 deletions

View File

@ -9,7 +9,7 @@ import PySimpleGUI as sg
GUI frameworks use, but there is no advantage to structuring you code in his manner. It adds GUI frameworks use, but there is no advantage to structuring you code in his manner. It adds
confusion, not clarity. confusion, not clarity.
The class version is 18 lines of code. The plain version is 11 lines of code. The class version is 18 lines of code. The plain version is 13 lines of code.
Two things about the class wrapper jump out as adding confusion: Two things about the class wrapper jump out as adding confusion:
1. Unneccessary fragmentation of the event loop - the button click code is pulled out of the loop entirely 1. Unneccessary fragmentation of the event loop - the button click code is pulled out of the loop entirely
@ -83,13 +83,14 @@ my_gui.run()
MMMMMMMMMMM MMMMMMMMMMM
''' '''
layout = [ [sg.Text('My layout')], def gui_function():
layout = [ [sg.Text('My layout')],
[sg.Input(key='-IN-')], [sg.Input(key='-IN-')],
[sg.Button('Go'), sg.Button('Exit')] ] [sg.Button('Go'), sg.Button('Exit')] ]
window = sg.Window('My new window', layout) window = sg.Window('My new window', layout)
while True: # Event Loop while True: # Event Loop
event, values = window.read() event, values = window.read()
if event in (sg.WIN_CLOSED, 'Exit'): if event in (sg.WIN_CLOSED, 'Exit'):
break break
@ -97,5 +98,6 @@ while True: # Event Loop
if event == 'Go': if event == 'Go':
sg.popup('Go button clicked', 'Input value:', values['-IN-']) sg.popup('Go button clicked', 'Input value:', values['-IN-'])
window.close() window.close()
gui_function()