|
9 | 9 | GUI frameworks use, but there is no advantage to structuring you code in his manner. It adds |
10 | 10 | confusion, not clarity. |
11 | 11 | |
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. |
13 | 13 | |
14 | 14 | Two things about the class wrapper jump out as adding confusion: |
15 | 15 | 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): |
83 | 83 | MMMMMMMMMMM |
84 | 84 | ''' |
85 | 85 |
|
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')] ] |
89 | 90 |
|
90 | | -window = sg.Window('My new window', layout) |
| 91 | + window = sg.Window('My new window', layout) |
91 | 92 |
|
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 |
96 | 97 |
|
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-']) |
99 | 100 |
|
100 | | -window.close() |
| 101 | + window.close() |
101 | 102 |
|
| 103 | +gui_function() |
0 commit comments