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
|
||||
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:
|
||||
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
|
||||
'''
|
||||
|
||||
layout = [ [sg.Text('My layout')],
|
||||
def gui_function():
|
||||
layout = [ [sg.Text('My layout')],
|
||||
[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()
|
||||
if event in (sg.WIN_CLOSED, 'Exit'):
|
||||
break
|
||||
|
@ -97,5 +98,6 @@ while True: # Event Loop
|
|||
if event == 'Go':
|
||||
sg.popup('Go button clicked', 'Input value:', values['-IN-'])
|
||||
|
||||
window.close()
|
||||
window.close()
|
||||
|
||||
gui_function()
|
||||
|
|
Loading…
Reference in New Issue