Skip to content

Commit eeb9539

Browse files
committed
Added a function around the functional example
1 parent b62648a commit eeb9539

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

DemoPrograms/Demo_Class_Wrapper.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
GUI frameworks use, but there is no advantage to structuring you code in his manner. It adds
1010
confusion, not clarity.
1111
12-
The class version is 18 lines of code. The plain version is 11 lines of code.
12+
The class version is 18 lines of code. The plain version is 13 lines of code.
1313
1414
Two things about the class wrapper jump out as adding confusion:
1515
1. Unneccessary fragmentation of the event loop - the button click code is pulled out of the loop entirely
@@ -83,19 +83,21 @@ def button_go(self):
8383
MMMMMMMMMMM
8484
'''
8585

86-
layout = [ [sg.Text('My layout')],
87-
[sg.Input(key='-IN-')],
88-
[sg.Button('Go'), sg.Button('Exit')] ]
86+
def gui_function():
87+
layout = [ [sg.Text('My layout')],
88+
[sg.Input(key='-IN-')],
89+
[sg.Button('Go'), sg.Button('Exit')] ]
8990

90-
window = sg.Window('My new window', layout)
91+
window = sg.Window('My new window', layout)
9192

92-
while True: # Event Loop
93-
event, values = window.read()
94-
if event in (sg.WIN_CLOSED, 'Exit'):
95-
break
93+
while True: # Event Loop
94+
event, values = window.read()
95+
if event in (sg.WIN_CLOSED, 'Exit'):
96+
break
9697

97-
if event == 'Go':
98-
sg.popup('Go button clicked', 'Input value:', values['-IN-'])
98+
if event == 'Go':
99+
sg.popup('Go button clicked', 'Input value:', values['-IN-'])
99100

100-
window.close()
101+
window.close()
101102

103+
gui_function()

0 commit comments

Comments
 (0)