Moved all demo programs into subfolder
This commit is contained in:
parent
a294d0a347
commit
1881bd7126
107 changed files with 51 additions and 144 deletions
60
DemoPrograms/Demo_Design_Patterns.py
Normal file
60
DemoPrograms/Demo_Design_Patterns.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
"""
|
||||
When creating a new PySimpleGUI program from scratch, start here.
|
||||
These are the accepted design patterns that cover the two primary use cases
|
||||
|
||||
1. A window that closes when a "submit" type button is clicked
|
||||
2. A persistent window that stays open after button clicks (uses an event loop)
|
||||
3. A persistent window that needs access to the elements' interface variables
|
||||
"""
|
||||
# ---------------------------------#
|
||||
# DESIGN PATTERN 1 - Simple Window #
|
||||
# ---------------------------------#
|
||||
import sys
|
||||
if sys.version_info[0] >= 3:
|
||||
import PySimpleGUI as sg
|
||||
else:
|
||||
import PySimpleGUI27 as sg
|
||||
|
||||
layout = [[ sg.Text('My layout') ]]
|
||||
|
||||
window = sg.Window('My window').Layout(layout)
|
||||
event, values = window.Read()
|
||||
|
||||
|
||||
# -------------------------------------#
|
||||
# DESIGN PATTERN 2 - Persistent Window #
|
||||
# -------------------------------------#
|
||||
import sys
|
||||
if sys.version_info[0] >= 3:
|
||||
import PySimpleGUI as sg
|
||||
else:
|
||||
import PySimpleGUI27 as sg
|
||||
|
||||
layout = [[ sg.Text('My layout') ]]
|
||||
|
||||
window = sg.Window('My new window').Layout(layout)
|
||||
|
||||
while True: # Event Loop
|
||||
event, values = window.Read()
|
||||
if event is None:
|
||||
break
|
||||
|
||||
# ------------------------------------------------------------------#
|
||||
# DESIGN PATTERN 3 - Persistent Window with "early update" required #
|
||||
# ------------------------------------------------------------------#
|
||||
import sys
|
||||
if sys.version_info[0] >= 3:
|
||||
import PySimpleGUI as sg
|
||||
else:
|
||||
import PySimpleGUI27 as sg
|
||||
|
||||
layout = [[ sg.Text('My layout') ]]
|
||||
|
||||
window = sg.Window('My new window').Layout(layout).Finalize()
|
||||
|
||||
# if you have operations on elements that must take place before the event loop, do them here
|
||||
|
||||
while True: # Event Loop
|
||||
event, values = window.Read()
|
||||
if event is None:
|
||||
break
|
Loading…
Add table
Add a link
Reference in a new issue