PySimpleGUI/Demo_Template.py

39 lines
1.1 KiB
Python
Raw Normal View History

#choose one of these are your starting point. Copy, paste, have fun
2018-09-27 20:24:09 +00:00
# ---------------------------------#
# DESIGN PATTERN 1 - Simple Window #
# ---------------------------------#
#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
2018-09-27 20:24:09 +00:00
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
2018-09-27 20:24:09 +00:00
layout = [[ sg.Text('My layout') ],
2018-10-29 00:01:03 +00:00
[ sg.CloseButton('Next Window')]]
2018-09-27 20:24:09 +00:00
window = sg.Window('My window').Layout(layout)
event, values = window.Read()
2018-09-27 20:24:09 +00:00
2018-10-29 00:01:03 +00:00
# --------------------------------------------------#
# DESIGN PATTERN 2 - Persistent Window (stays open) #
# --------------------------------------------------#
2018-09-27 20:24:09 +00:00
#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
2018-09-27 20:24:09 +00:00
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
2018-09-27 20:24:09 +00:00
2018-10-29 00:01:03 +00:00
layout = [[ sg.Text('My Window') ],
[ sg.Button('Read The Window')]]
2018-09-27 20:24:09 +00:00
2018-10-29 00:01:03 +00:00
window = sg.Window('My Window Title').Layout(layout)
2018-09-27 20:24:09 +00:00
2018-10-29 00:01:03 +00:00
while True: # Event Loop
event, values = window.Read()
2018-10-29 00:01:03 +00:00
if event is None: # if window closed with X
break
print(event, values)