Skip to content

Commit e29acb9

Browse files
committed
New Demo - Class wrapper
1 parent e6c1a14 commit e29acb9

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

DemoPrograms/Demo_Class_Wrapper.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import PySimpleGUI as sg
2+
3+
"""
4+
Demo - Class wrapper
5+
6+
Using a class to encapsulate PySimpleGUI Window creation & event loop
7+
8+
Copyright 2022 PySimpleGUI
9+
"""
10+
11+
class SampleGUI():
12+
13+
def __init__(self):
14+
self.layout = [ [sg.Text('My layout')],
15+
[sg.Input(key='-IN-')],
16+
[sg.Button('Go'), sg.Button('Exit')] ]
17+
18+
self.window = sg.Window('My new window', self.layout)
19+
20+
def run(self):
21+
while True: # Event Loop
22+
self.event, self.values = self.window.read()
23+
if self.event in (sg.WIN_CLOSED, 'Exit'):
24+
break
25+
26+
if self.event == 'Go':
27+
self.button_go()
28+
29+
self.window.close()
30+
31+
def button_go(self):
32+
sg.popup('Go button clicked', 'Input value:', self.values['-IN-'])
33+
34+
# Create the class
35+
my_gui = SampleGUI()
36+
# run the event loop
37+
my_gui.run()

0 commit comments

Comments
 (0)