Added a function around the functional example
This commit is contained in:
parent
b62648aa23
commit
eeb95398e0
|
@ -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,19 +83,21 @@ my_gui.run()
|
||||||
MMMMMMMMMMM
|
MMMMMMMMMMM
|
||||||
'''
|
'''
|
||||||
|
|
||||||
layout = [ [sg.Text('My layout')],
|
def gui_function():
|
||||||
[sg.Input(key='-IN-')],
|
layout = [ [sg.Text('My layout')],
|
||||||
[sg.Button('Go'), sg.Button('Exit')] ]
|
[sg.Input(key='-IN-')],
|
||||||
|
[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
|
||||||
|
|
||||||
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()
|
||||||
|
|
Loading…
Reference in New Issue