File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments