forked from PySimpleGUI/PySimpleGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo_Class_Wrapper.py
More file actions
37 lines (26 loc) · 909 Bytes
/
Demo_Class_Wrapper.py
File metadata and controls
37 lines (26 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import PySimpleGUI as sg
"""
Demo - Class wrapper
Using a class to encapsulate PySimpleGUI Window creation & event loop
Copyright 2022 PySimpleGUI
"""
class SampleGUI():
def __init__(self):
self.layout = [ [sg.Text('My layout')],
[sg.Input(key='-IN-')],
[sg.Button('Go'), sg.Button('Exit')] ]
self.window = sg.Window('My new window', self.layout)
def run(self):
while True: # Event Loop
self.event, self.values = self.window.read()
if self.event in (sg.WIN_CLOSED, 'Exit'):
break
if self.event == 'Go':
self.button_go()
self.window.close()
def button_go(self):
sg.popup('Go button clicked', 'Input value:', self.values['-IN-'])
# Create the class
my_gui = SampleGUI()
# run the event loop
my_gui.run()