Added import code for BOTH 2.,7 and 3
This commit is contained in:
parent
8b4185988f
commit
ab98ea20eb
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env Python3
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
sg.ChangeLookAndFeel('GreenTan')
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
"""
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
import PySimpleGUI as sg
|
||||
import winsound
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
import winsound
|
||||
|
||||
|
||||
sg.ChangeLookAndFeel('Dark')
|
||||
sg.SetOptions(element_padding=(0,0))
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
import PySimpleGUI as sg
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
"""
|
||||
Demonstrates using a "tight" layout with a Dark theme.
|
||||
Shows how button states can be controlled by a user application. The program manages the disabled/enabled
|
||||
|
@ -15,15 +20,15 @@ layout = [[sg.T('User:', pad=((3,0),0)), sg.OptionMenu(values = ('User 1', 'User
|
|||
[sg.ReadButton('Start', button_color=('white', 'black'), key='Start'),
|
||||
sg.ReadButton('Stop', button_color=('white', 'black'), key='Stop'),
|
||||
sg.ReadButton('Reset', button_color=('white', 'firebrick3'), key='Reset'),
|
||||
sg.ReadButton('Submit', button_color=('white', 'springgreen4'), key='Submit')]
|
||||
]
|
||||
sg.ReadButton('Submit', button_color=('white', 'springgreen4'), key='Submit')]]
|
||||
|
||||
window = sg.Window("Time Tracker", default_element_size=(12,1), text_justification='r', auto_size_text=False, auto_size_buttons=False,
|
||||
default_button_element_size=(12,1)).Layout(layout)
|
||||
window.Finalize()
|
||||
window.FindElement('Stop').Update(disabled=True)
|
||||
window.FindElement('Reset').Update(disabled=True)
|
||||
window.FindElement('Submit').Update(disabled=True)
|
||||
default_button_element_size=(12,1)).Layout(layout).Finalize()
|
||||
|
||||
|
||||
for key, state in {'Start': False, 'Stop': True, 'Reset': True, 'Submit': True}.items():
|
||||
window.FindElement(key).Update(disabled=state)
|
||||
|
||||
recording = have_data = False
|
||||
while True:
|
||||
button, values = window.Read()
|
||||
|
@ -31,27 +36,17 @@ while True:
|
|||
if button is None:
|
||||
sys.exit(69)
|
||||
if button is 'Start':
|
||||
window.FindElement('Start').Update(disabled=True)
|
||||
window.FindElement('Stop').Update(disabled=False)
|
||||
window.FindElement('Reset').Update(disabled=False)
|
||||
window.FindElement('Submit').Update(disabled=True)
|
||||
for key, state in {'Start':True, 'Stop':False, 'Reset':False, 'Submit':True}.items():
|
||||
window.FindElement(key).Update(disabled=state)
|
||||
recording = True
|
||||
elif button is 'Stop' and recording:
|
||||
window.FindElement('Stop').Update(disabled=True)
|
||||
window.FindElement('Start').Update(disabled=False)
|
||||
window.FindElement('Submit').Update(disabled=False)
|
||||
[window.FindElement(key).Update(disabled=value) for key,value in {'Start':False, 'Stop':True, 'Reset':False, 'Submit':False}.items()]
|
||||
recording = False
|
||||
have_data = True
|
||||
elif button is 'Reset':
|
||||
window.FindElement('Stop').Update(disabled=True)
|
||||
window.FindElement('Start').Update(disabled=False)
|
||||
window.FindElement('Submit').Update(disabled=True)
|
||||
window.FindElement('Reset').Update(disabled=False)
|
||||
[window.FindElement(key).Update(disabled=value) for key,value in {'Start':False, 'Stop':True, 'Reset':True, 'Submit':True}.items()]
|
||||
recording = False
|
||||
have_data = False
|
||||
elif button is 'Submit' and have_data:
|
||||
window.FindElement('Stop').Update(disabled=True)
|
||||
window.FindElement('Start').Update(disabled=False)
|
||||
window.FindElement('Submit').Update(disabled=True)
|
||||
window.FindElement('Reset').Update(disabled=False)
|
||||
[window.FindElement(key).Update(disabled=value) for key,value in {'Start':False, 'Stop':True, 'Reset':True, 'Submit':False}.items()]
|
||||
recording = False
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
layout = [[sg.T('Calendar Test')],
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
|
||||
layout = [
|
||||
[sg.Canvas(size=(150, 150), background_color='red', key='canvas')],
|
||||
[sg.T('Change circle color to:'), sg.ReadButton('Red'), sg.ReadButton('Blue')]
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
import PySimpleGUI as sg
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
'''
|
||||
A chat window. Add call to your send-routine, print the response and you're done
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
import PySimpleGUI as sg
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
'''
|
||||
A chatbot with history
|
||||
Scroll up and down through prior commands using the arrow keys
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
from chatterbot import ChatBot
|
||||
import chatterbot.utils
|
||||
import sys
|
||||
|
||||
|
||||
'''
|
||||
Demo_Chatterbot.py
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
MY_WINDOW_ICON = 'E:\\TheRealMyDocs\\Icons\\The Planets\\jupiter.ico'
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
"""
|
||||
Color names courtesy of Big Daddy's Wiki-Python
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
sg.ChangeLookAndFeel('BlueMono')
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import PySimpleGUI as sg
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
# sg.SetOptions(button_color=sg.COLOR_SYSTEM_DEFAULT)
|
||||
|
||||
def GetFilesToCompare():
|
||||
|
|
|
@ -0,0 +1,793 @@
|
|||
|
||||
|
||||
# import PySimpleGUI as sg
|
||||
import inspect
|
||||
|
||||
def SimpleDataEntry():
|
||||
"""Simple Data Entry - Return Values As List
|
||||
Same GUI screen except the return values are in a list instead of a dictionary and doesn't have initial values.
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
# Very basic window. Return values as a list
|
||||
window = sg.Window('Simple data entry form') # begin with a blank form
|
||||
|
||||
layout = [
|
||||
[sg.Text('Please enter your Name, Address, Phone')],
|
||||
[sg.Text('Name', size=(15, 1)), sg.InputText()],
|
||||
[sg.Text('Address', size=(15, 1)), sg.InputText()],
|
||||
[sg.Text('Phone', size=(15, 1)), sg.InputText()],
|
||||
[sg.Submit(), sg.Cancel()]
|
||||
]
|
||||
|
||||
button, values = window.LayoutAndRead(layout)
|
||||
|
||||
print(button, values[0], values[1], values[2])
|
||||
|
||||
def SimpleReturnAsDict():
|
||||
"""
|
||||
Simple data entry - Return Values As Dictionary
|
||||
A simple form with default values. Results returned in a dictionary. Does not use a context manager
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
|
||||
# Very basic window. Return values as a dictionary
|
||||
window = sg.Window('Simple data entry form') # begin with a blank form
|
||||
|
||||
layout = [
|
||||
[sg.Text('Please enter your Name, Address, Phone')],
|
||||
[sg.Text('Name', size=(15, 1)), sg.InputText('name', key='name')],
|
||||
[sg.Text('Address', size=(15, 1)), sg.InputText('address', key='address')],
|
||||
[sg.Text('Phone', size=(15, 1)), sg.InputText('phone', key='phone')],
|
||||
[sg.Submit(), sg.Cancel()]
|
||||
]
|
||||
|
||||
button, values = window.LayoutAndRead(layout)
|
||||
|
||||
print(button, values['name'], values['address'], values['phone'])
|
||||
|
||||
def FileBrowse():
|
||||
"""
|
||||
Simple File Browse
|
||||
Browse for a filename that is populated into the input field.
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
|
||||
with sg.Window('SHA-1 & 256 Hash') as form:
|
||||
form_rows = [[sg.Text('SHA-1 and SHA-256 Hashes for the file')],
|
||||
[sg.InputText(), sg.FileBrowse()],
|
||||
[sg.Submit(), sg.Cancel()]]
|
||||
(button, (source_filename,)) = window.LayoutAndRead(form_rows)
|
||||
|
||||
print(button, source_filename)
|
||||
|
||||
def GUIAddOn():
|
||||
"""
|
||||
Add GUI to Front-End of Script
|
||||
Quickly add a GUI allowing the user to browse for a filename if a filename is not supplied on the command line using this 1-line GUI. It's the best of both worlds.
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
import sys
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
button, (fname,) = sg.Window('My Script').LayoutAndRead([[sg.T('Document to open')],
|
||||
[sg.In(), sg.FileBrowse()],
|
||||
[sg.Open(), sg.Cancel()]])
|
||||
else:
|
||||
fname = sys.argv[1]
|
||||
|
||||
if not fname:
|
||||
sg.Popup("Cancel", "No filename supplied")
|
||||
# raise SystemExit("Cancelling: no filename supplied")
|
||||
|
||||
def Compare2Files():
|
||||
"""
|
||||
Compare 2 Files
|
||||
Browse to get 2 file names that can be then compared. Uses a context manager
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
|
||||
with sg.Window('File Compare') as form:
|
||||
form_rows = [[sg.Text('Enter 2 files to comare')],
|
||||
[sg.Text('File 1', size=(8, 1)), sg.InputText(), sg.FileBrowse()],
|
||||
[sg.Text('File 2', size=(8, 1)), sg.InputText(), sg.FileBrowse()],
|
||||
[sg.Submit(), sg.Cancel()]]
|
||||
|
||||
button, values = window.LayoutAndRead(form_rows)
|
||||
|
||||
print(button, values)
|
||||
|
||||
def AllWidgetsWithContext():
|
||||
"""
|
||||
Nearly All Widgets with Green Color Theme with Context Manager
|
||||
Example of nearly all of the widgets in a single window. Uses a customized color scheme. This recipe uses a context manager, the preferred method.
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
# Green & tan color scheme
|
||||
sg.ChangeLookAndFeel('GreenTan')
|
||||
|
||||
|
||||
# sg.ChangeLookAndFeel('GreenTan')
|
||||
|
||||
with sg.Window('Everything bagel', default_element_size=(40, 1), grab_anywhere=False) as form:
|
||||
|
||||
column1 = [[sg.Text('Column 1', background_color='#F7F3EC', justification='center', size=(10, 1))],
|
||||
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 1')],
|
||||
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 2')],
|
||||
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 3')]]
|
||||
|
||||
layout = [
|
||||
[sg.Text('All graphic widgets in one form!', size=(30, 1), font=("Helvetica", 25))],
|
||||
[sg.Text('Here is some text.... and a place to enter text')],
|
||||
[sg.InputText('This is my text')],
|
||||
[sg.Checkbox('Checkbox'), sg.Checkbox('My second checkbox!', default=True)],
|
||||
[sg.Radio('My first Radio! ', "RADIO1", default=True), sg.Radio('My second Radio!', "RADIO1")],
|
||||
[sg.Multiline(default_text='This is the default Text should you decide not to type anything', size=(35, 3)),
|
||||
sg.Multiline(default_text='A second multi-line', size=(35, 3))],
|
||||
[sg.InputCombo(('Combobox 1', 'Combobox 2'), size=(20, 1)),
|
||||
sg.Slider(range=(1, 100), orientation='h', size=(34, 20), default_value=85)],
|
||||
[sg.InputOptionMenu(('Menu Option 1', 'Menu Option 2', 'Menu Option 3'))],
|
||||
[sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'), size=(30, 3)),
|
||||
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=25),
|
||||
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=75),
|
||||
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=10),
|
||||
sg.Column(column1, background_color='#F7F3EC')],
|
||||
[sg.Text('_' * 80)],
|
||||
[sg.Text('Choose A Folder', size=(35, 1))],
|
||||
[sg.Text('Your Folder', size=(15, 1), auto_size_text=False, justification='right'),
|
||||
sg.InputText('Default Folder'), sg.FolderBrowse()],
|
||||
[sg.Submit(), sg.Cancel()]
|
||||
]
|
||||
|
||||
button, values = window.LayoutAndRead(layout)
|
||||
|
||||
def AllWidgetsNoContext():
|
||||
"""
|
||||
All Widgets No Context Manager
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
|
||||
sg.ChangeLookAndFeel('GreenTan')
|
||||
|
||||
window = sg.Window('Everything bagel', default_element_size=(40, 1), grab_anywhere=False)
|
||||
|
||||
column1 = [[sg.Text('Column 1', background_color='#F7F3EC', justification='center', size=(10, 1))],
|
||||
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 1')],
|
||||
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 2')],
|
||||
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 3')]]
|
||||
|
||||
layout = [
|
||||
[sg.Text('All graphic widgets in one form!', size=(30, 1), font=("Helvetica", 25))],
|
||||
[sg.Text('Here is some text.... and a place to enter text')],
|
||||
[sg.InputText('This is my text')],
|
||||
[sg.Checkbox('Checkbox'), sg.Checkbox('My second checkbox!', default=True)],
|
||||
[sg.Radio('My first Radio! ', "RADIO1", default=True), sg.Radio('My second Radio!', "RADIO1")],
|
||||
[sg.Multiline(default_text='This is the default Text should you decide not to type anything', size=(35, 3)),
|
||||
sg.Multiline(default_text='A second multi-line', size=(35, 3))],
|
||||
[sg.InputCombo(('Combobox 1', 'Combobox 2'), size=(20, 1)),
|
||||
sg.Slider(range=(1, 100), orientation='h', size=(34, 20), default_value=85)],
|
||||
[sg.InputOptionMenu(('Menu Option 1', 'Menu Option 2', 'Menu Option 3'))],
|
||||
[sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'), size=(30, 3)),
|
||||
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=25),
|
||||
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=75),
|
||||
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=10),
|
||||
sg.Column(column1, background_color='#F7F3EC')],
|
||||
[sg.Text('_' * 80)],
|
||||
[sg.Text('Choose A Folder', size=(35, 1))],
|
||||
[sg.Text('Your Folder', size=(15, 1), auto_size_text=False, justification='right'),
|
||||
sg.InputText('Default Folder'), sg.FolderBrowse()],
|
||||
[sg.Submit(), sg.Cancel()]
|
||||
]
|
||||
|
||||
button, values = window.LayoutAndRead(layout)
|
||||
|
||||
def NonBlockingWithUpdates():
|
||||
"""
|
||||
Non-Blocking Form With Periodic Update
|
||||
An async form that has a button read loop. A Text Element is updated periodically with a running timer. There is no context manager for this recipe because the loop that reads the form is likely to be some distance away from where the form was initialized.
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
import time
|
||||
|
||||
window = sg.Window('Running Timer')
|
||||
# create a text element that will be updated periodically
|
||||
|
||||
form_rows = [[sg.Text('Stopwatch', size=(20,2), justification='center')],
|
||||
[ sg.Text('', size=(10, 2), font=('Helvetica', 20), justification='center', key='output')],
|
||||
[sg.T(' ' * 5), sg.ReadButton('Start/Stop', focus=True), sg.Quit()]]
|
||||
|
||||
window.LayoutAndRead(form_rows, non_blocking=True)
|
||||
|
||||
timer_running = True
|
||||
i = 0
|
||||
# loop to process user clicks
|
||||
while True:
|
||||
i += 1 * (timer_running is True)
|
||||
button, values = window.ReadNonBlocking()
|
||||
if values is None or button == 'Quit': # if user closed the window using X or clicked Quit button
|
||||
break
|
||||
elif button == 'Start/Stop':
|
||||
timer_running = not timer_running
|
||||
window.FindElement('output').Update('{:02d}:{:02d}.{:02d}'.format((i // 100) // 60, (i // 100) % 60, i % 100))
|
||||
|
||||
time.sleep(.01)
|
||||
# if the loop finished then need to close the form for the user
|
||||
window.CloseNonBlocking()
|
||||
|
||||
def NonBlockingWithContext():
|
||||
"""
|
||||
Async Form (Non-Blocking) with Context Manager
|
||||
Like the previous recipe, this form is an async window. The difference is that this form uses a context manager.
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
import time
|
||||
|
||||
with sg.Window('Running Timer') as form:
|
||||
layout = [[sg.Text('Non blocking GUI with updates', justification='center')],
|
||||
[sg.Text('', size=(10, 2), font=('Helvetica', 20), text_color='red', justification='center', key='output')],
|
||||
[sg.T(' ' * 15), sg.Quit()]]
|
||||
window.LayoutAndRead(layout, non_blocking=True)
|
||||
|
||||
for i in range(1, 500):
|
||||
window.FindElement('output').Update('{:02d}:{:02d}.{:02d}'.format((i // 100) // 60, (i // 100) % 60, i % 100))
|
||||
button, values = window.ReadNonBlocking()
|
||||
if values is None or button == 'Quit': # if user closed the window using X
|
||||
break
|
||||
time.sleep(.01)
|
||||
else:
|
||||
# if the loop finished then need to close the form for the user
|
||||
window.CloseNonBlocking()
|
||||
|
||||
def CallbackSimulation():
|
||||
"""
|
||||
Callback Function Simulation
|
||||
The architecture of some programs works better with button callbacks instead of handling in-line. While button callbacks are part of the PySimpleGUI implementation, they are not directly exposed to the caller. The way to get the same result as callbacks is to simulate them with a recipe like this one.
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
|
||||
# This design pattern simulates button callbacks
|
||||
# Note that callbacks are NOT a part of the package's interface to the
|
||||
# caller intentionally. The underlying implementation actually does use
|
||||
# tkinter callbacks. They are simply hidden from the user.
|
||||
|
||||
# The callback functions
|
||||
def button1():
|
||||
print('Button 1 callback')
|
||||
|
||||
def button2():
|
||||
print('Button 2 callback')
|
||||
|
||||
# Create a standard form
|
||||
window = sg.Window('Button callback example')
|
||||
# Layout the design of the GUI
|
||||
layout = [[sg.Text('Please click a button')],
|
||||
[sg.ReadButton('1'), sg.ReadButton('2'), sg.Quit()]]
|
||||
# Show the form to the user
|
||||
window.Layout(layout)
|
||||
|
||||
# Event loop. Read buttons, make callbacks
|
||||
while True:
|
||||
# Read the form
|
||||
button, value = window.Read()
|
||||
# Take appropriate action based on button
|
||||
if button == '1':
|
||||
button1()
|
||||
elif button == '2':
|
||||
button2()
|
||||
elif button =='Quit' or button is None:
|
||||
break
|
||||
|
||||
# All done!
|
||||
sg.PopupOk('Done')
|
||||
|
||||
def RealtimeButtons():
|
||||
"""
|
||||
Realtime Buttons (Good For Raspberry Pi)
|
||||
This recipe implements a remote control interface for a robot. There are 4 directions, forward, reverse, left, right. When a button is clicked, PySimpleGUI immediately returns button events for as long as the buttons is held down. When released, the button events stop. This is an async/non-blocking window.
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
|
||||
# Make a form, but don't use context manager
|
||||
window = sg.Window('Robotics Remote Control')
|
||||
|
||||
form_rows = [[sg.Text('Robotics Remote Control')],
|
||||
[sg.T(' ' * 10), sg.RealtimeButton('Forward')],
|
||||
[sg.RealtimeButton('Left'), sg.T(' ' * 15), sg.RealtimeButton('Right')],
|
||||
[sg.T(' ' * 10), sg.RealtimeButton('Reverse')],
|
||||
[sg.T('')],
|
||||
[sg.Quit(button_color=('black', 'orange'))]
|
||||
]
|
||||
|
||||
window.LayoutAndRead(form_rows, non_blocking=True)
|
||||
|
||||
#
|
||||
# Some place later in your code...
|
||||
# You need to perform a ReadNonBlocking on your form every now and then or
|
||||
# else it won't refresh.
|
||||
#
|
||||
# your program's main loop
|
||||
while (True):
|
||||
# This is the code that reads and updates your window
|
||||
button, values = window.ReadNonBlocking()
|
||||
if button is not None:
|
||||
print(button)
|
||||
if button is 'Quit' or values is None:
|
||||
break
|
||||
|
||||
window.CloseNonBlocking()
|
||||
|
||||
def EasyProgressMeter():
|
||||
"""
|
||||
Easy Progress Meter
|
||||
This recipe shows just how easy it is to add a progress meter to your code.
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
|
||||
for i in range(1000):
|
||||
sg.EasyProgressMeter('Easy Meter Example', i+1, 1000)
|
||||
|
||||
def TabbedForm():
|
||||
"""
|
||||
Tabbed Form
|
||||
Tabbed forms are easy to make and use in PySimpleGUI. You simple may your layouts for each tab and then instead of LayoutAndRead you call ShowTabbedwindow. Results are returned as a list of form results. Each tab acts like a single window.
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
|
||||
with sg.Window('') as form:
|
||||
with sg.Window('') as form2:
|
||||
|
||||
layout_tab_1 = [[sg.Text('First tab', size=(20, 1), font=('helvetica', 15))],
|
||||
[sg.InputText(), sg.Text('Enter some info')],
|
||||
[sg.Submit(button_color=('red', 'yellow')), sg.Cancel(button_color=('white', 'blue'))]]
|
||||
|
||||
layout_tab_2 = [[sg.Text('Second Tab', size=(20, 1), font=('helvetica', 15))],
|
||||
[sg.InputText(), sg.Text('Enter some info')],
|
||||
[sg.Submit(button_color=('red', 'yellow')), sg.Cancel(button_color=('white', 'blue'))]]
|
||||
|
||||
results = sg.ShowTabbedForm('Tabbed form example', (form, layout_tab_1, 'First Tab'),
|
||||
(form2, layout_tab_2,'Second Tab'))
|
||||
|
||||
sg.Popup(results)
|
||||
|
||||
def MediaPlayer():
|
||||
"""
|
||||
Button Graphics (Media Player)
|
||||
Buttons can have PNG of GIF images on them. This Media Player recipe requires 4 images in order to function correctly. The background is set to the same color as the button background so that they blend together.
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
|
||||
background = '#F0F0F0'
|
||||
# Set the backgrounds the same as the background on the buttons
|
||||
sg.SetOptions(background_color=background, element_background_color=background)
|
||||
# Images are located in a subfolder in the Demo Media Player.py folder
|
||||
image_pause = './ButtonGraphics/Pause.png'
|
||||
image_restart = './ButtonGraphics/Restart.png'
|
||||
image_next = './ButtonGraphics/Next.png'
|
||||
image_exit = './ButtonGraphics/Exit.png'
|
||||
|
||||
# Open a form, note that context manager can't be used generally speaking for async forms
|
||||
window = sg.Window('Media File Player', default_element_size=(20, 1),
|
||||
font=("Helvetica", 25))
|
||||
# define layout of the rows
|
||||
layout = [[sg.Text('Media File Player', size=(17, 1), font=("Helvetica", 25))],
|
||||
[sg.Text('', size=(15, 2), font=("Helvetica", 14), key='out')],
|
||||
[sg.ReadButton('Restart Song', button_color=(background, background),
|
||||
image_filename=image_restart, image_size=(50, 50), image_subsample=2, border_width=0),
|
||||
sg.Text(' ' * 2),
|
||||
sg.ReadButton('Pause', button_color=(background, background),
|
||||
image_filename=image_pause, image_size=(50, 50), image_subsample=2, border_width=0),
|
||||
sg.Text(' ' * 2),
|
||||
sg.ReadButton('Next', button_color=(background, background),
|
||||
image_filename=image_next, image_size=(50, 50), image_subsample=2, border_width=0),
|
||||
sg.Text(' ' * 2),
|
||||
sg.Text(' ' * 2), sg.Button('Exit', button_color=(background, background),
|
||||
image_filename=image_exit, image_size=(50, 50), image_subsample=2,
|
||||
border_width=0)],
|
||||
[sg.Text('_' * 20)],
|
||||
[sg.Text(' ' * 30)],
|
||||
[sg.Slider(range=(-10, 10), default_value=0, size=(10, 20), orientation='vertical',
|
||||
font=("Helvetica", 15)),
|
||||
sg.Text(' ' * 2),
|
||||
sg.Slider(range=(-10, 10), default_value=0, size=(10, 20), orientation='vertical',
|
||||
font=("Helvetica", 15)),
|
||||
sg.Text(' ' * 8),
|
||||
sg.Slider(range=(-10, 10), default_value=0, size=(10, 20), orientation='vertical',
|
||||
font=("Helvetica", 15))],
|
||||
[sg.Text('Bass', font=("Helvetica", 15), size=(6, 1)),
|
||||
sg.Text('Treble', font=("Helvetica", 15), size=(10, 1)),
|
||||
sg.Text('Volume', font=("Helvetica", 15), size=(7, 1))] ]
|
||||
|
||||
# Call the same LayoutAndRead but indicate the form is non-blocking
|
||||
window.LayoutAndRead(layout, non_blocking=True)
|
||||
# Our event loop
|
||||
while (True):
|
||||
# Read the form (this call will not block)
|
||||
button, values = window.ReadNonBlocking()
|
||||
if button == 'Exit' or values is None:
|
||||
break
|
||||
# If a button was pressed, display it on the GUI by updating the text element
|
||||
if button:
|
||||
window.FindElement('out').Update(button)
|
||||
|
||||
def ScriptLauncher():
|
||||
"""
|
||||
Script Launcher - Persistent Form
|
||||
This form doesn't close after button clicks. To achieve this the buttons are specified as sg.ReadButton instead of sg.Button. The exception to this is the EXIT button. Clicking it will close the window. This program will run commands and display the output in the scrollable window.
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
import subprocess
|
||||
|
||||
def Launcher():
|
||||
|
||||
window = sg.Window('Script launcher')
|
||||
|
||||
layout = [
|
||||
[sg.Text('Script output....', size=(40, 1))],
|
||||
[sg.Output(size=(88, 20))],
|
||||
[sg.ReadButton('script1'), sg.ReadButton('script2'), sg.Button('EXIT')],
|
||||
[sg.Text('Manual command', size=(15,1)), sg.InputText(focus=True), sg.ReadButton('Run', bind_return_key=True)]
|
||||
]
|
||||
|
||||
window.Layout(layout)
|
||||
|
||||
# ---===--- Loop taking in user input and using it to query HowDoI --- #
|
||||
while True:
|
||||
(button, value) = window.Read()
|
||||
if button == 'EXIT' or button is None:
|
||||
break # exit button clicked
|
||||
if button == 'script1':
|
||||
ExecuteCommandSubprocess('pip','list')
|
||||
elif button == 'script2':
|
||||
ExecuteCommandSubprocess('python', '--version')
|
||||
elif button == 'Run':
|
||||
ExecuteCommandSubprocess(value[0])
|
||||
|
||||
|
||||
def ExecuteCommandSubprocess(command, *args):
|
||||
try:
|
||||
expanded_args = []
|
||||
for a in args:
|
||||
expanded_args += a
|
||||
sp = subprocess.Popen([command,expanded_args], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
out, err = sp.communicate()
|
||||
if out:
|
||||
print(out.decode("utf-8"))
|
||||
if err:
|
||||
print(err.decode("utf-8"))
|
||||
except: pass
|
||||
|
||||
Launcher()
|
||||
|
||||
def MachineLearning():
|
||||
"""
|
||||
Machine Learning GUI
|
||||
A standard non-blocking GUI with lots of inputs.
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
|
||||
sg.ChangeLookAndFeel('LightGreen')
|
||||
|
||||
sg.SetOptions(text_justification='right')
|
||||
|
||||
window = sg.Window('Machine Learning Front End', font=("Helvetica", 12)) # begin with a blank form
|
||||
|
||||
layout = [[sg.Text('Machine Learning Command Line Parameters', font=('Helvetica', 16))],
|
||||
[sg.Text('Passes', size=(15, 1)), sg.Spin(values=[i for i in range(1, 1000)], initial_value=20, size=(6, 1)),
|
||||
sg.Text('Steps', size=(18, 1)), sg.Spin(values=[i for i in range(1, 1000)], initial_value=20, size=(6, 1))],
|
||||
[sg.Text('ooa', size=(15, 1)), sg.In(default_text='6', size=(10, 1)), sg.Text('nn', size=(15, 1)), sg.In(default_text='10', size=(10, 1))],
|
||||
[sg.Text('q', size=(15, 1)), sg.In(default_text='ff', size=(10, 1)), sg.Text('ngram', size=(15, 1)), sg.In(default_text='5', size=(10, 1))],
|
||||
[sg.Text('l', size=(15, 1)), sg.In(default_text='0.4', size=(10, 1)), sg.Text('Layers', size=(15, 1)), sg.Drop(values=('BatchNorm', 'other'),auto_size_text=True)],
|
||||
[sg.Text('_' * 100, size=(65, 1))],
|
||||
[sg.Text('Flags', font=('Helvetica', 15), justification='left')],
|
||||
[sg.Checkbox('Normalize', size=(12, 1), default=True), sg.Checkbox('Verbose', size=(20, 1))],
|
||||
[sg.Checkbox('Cluster', size=(12, 1)), sg.Checkbox('Flush Output', size=(20, 1), default=True)],
|
||||
[sg.Checkbox('Write Results', size=(12, 1)), sg.Checkbox('Keep Intermediate Data', size=(20, 1))],
|
||||
[sg.Text('_' * 100, size=(65, 1))],
|
||||
[sg.Text('Loss Functions', font=('Helvetica', 15), justification='left')],
|
||||
[sg.Radio('Cross-Entropy', 'loss', size=(12, 1)), sg.Radio('Logistic', 'loss', default=True, size=(12, 1))],
|
||||
[sg.Radio('Hinge', 'loss', size=(12, 1)), sg.Radio('Huber', 'loss', size=(12, 1))],
|
||||
[sg.Radio('Kullerback', 'loss', size=(12, 1)), sg.Radio('MAE(L1)', 'loss', size=(12, 1))],
|
||||
[sg.Radio('MSE(L2)', 'loss', size=(12, 1)), sg.Radio('MB(L0)', 'loss', size=(12, 1))],
|
||||
[sg.Submit(), sg.Cancel()]]
|
||||
|
||||
button, values = window.LayoutAndRead(layout)
|
||||
|
||||
def CustromProgressMeter():
|
||||
""""
|
||||
Custom Progress Meter / Progress Bar
|
||||
Perhaps you don't want all the statistics that the EasyProgressMeter provides and want to create your own progress bar. Use this recipe to do just that.
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
|
||||
def CustomMeter():
|
||||
# create the progress bar element
|
||||
progress_bar = sg.ProgressBar(10000, orientation='h', size=(20,20))
|
||||
# layout the form
|
||||
layout = [[sg.Text('A custom progress meter')],
|
||||
[progress_bar],
|
||||
[sg.Cancel()]]
|
||||
|
||||
# create the form
|
||||
window = sg.Window('Custom Progress Meter')
|
||||
# display the form as a non-blocking form
|
||||
window.LayoutAndRead(layout, non_blocking=True)
|
||||
# loop that would normally do something useful
|
||||
for i in range(10000):
|
||||
# check to see if the cancel button was clicked and exit loop if clicked
|
||||
button, values = window.ReadNonBlocking()
|
||||
if button == 'Cancel' or values == None:
|
||||
break
|
||||
# update bar with loop value +1 so that bar eventually reaches the maximum
|
||||
progress_bar.UpdateBar(i+1)
|
||||
# done with loop... need to destroy the window as it's still open
|
||||
window.CloseNonBlocking()
|
||||
|
||||
CustomMeter()
|
||||
|
||||
def OneLineGUI():
|
||||
"""
|
||||
The One-Line GUI
|
||||
For those of you into super-compact code, a complete customized GUI can be specified, shown, and received the results using a single line of Python code. The way this is done is to combine the call to Window and the call to LayoutAndRead. Window returns a Window object which has the LayoutAndRead method.
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
|
||||
layout = [[sg.Text('Filename')],
|
||||
[sg.Input(), sg.FileBrowse()],
|
||||
[sg.OK(), sg.Cancel()] ]
|
||||
|
||||
button, (number,) = sg.Window('Get filename example').LayoutAndRead(layout)
|
||||
|
||||
"""
|
||||
you can write this line of code for the exact same result (OK, two lines with the import):
|
||||
"""
|
||||
# import PySimpleGUI as sg
|
||||
|
||||
button, (filename,) = sg.Window('Get filename example'). LayoutAndRead([[sg.Text('Filename')], [sg.Input(), sg.FileBrowse()], [sg.OK(), sg.Cancel()] ])
|
||||
|
||||
def MultipleColumns():
|
||||
"""
|
||||
Multiple Columns
|
||||
Starting in version 2.9 (not yet released but you can get from current GitHub) you can use the Column Element. A Column is required when you have a tall element to the left of smaller elements.
|
||||
|
||||
This example uses a Column. There is a Listbox on the left that is 3 rows high. To the right of it are 3 single rows of text and input. These 3 rows are in a Column Element.
|
||||
|
||||
To make it easier to see the Column in the window, the Column background has been shaded blue. The code is wordier than normal due to the blue shading. Each element in the column needs to have the color set to match blue background.
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
|
||||
# Demo of how columns work
|
||||
# Form has on row 1 a vertical slider followed by a COLUMN with 7 rows
|
||||
# Prior to the Column element, this layout was not possible
|
||||
# Columns layouts look identical to form layouts, they are a list of lists of elements.
|
||||
|
||||
# sg.ChangeLookAndFeel('BlueMono')
|
||||
|
||||
# Column layout
|
||||
col = [[sg.Text('col Row 1', text_color='white', background_color='blue')],
|
||||
[sg.Text('col Row 2', text_color='white', background_color='blue'), sg.Input('col input 1')],
|
||||
[sg.Text('col Row 3', text_color='white', background_color='blue'), sg.Input('col input 2')]]
|
||||
|
||||
layout = [[sg.Listbox(values=('Listbox Item 1', 'Listbox Item 2', 'Listbox Item 3'), select_mode=sg.LISTBOX_SELECT_MODE_MULTIPLE, size=(20,3)), sg.Column(col, background_color='blue')],
|
||||
[sg.Input('Last input')],
|
||||
[sg.OK()]]
|
||||
|
||||
# Display the form and get values
|
||||
# If you're willing to not use the "context manager" design pattern, then it's possible
|
||||
# to collapse the form display and read down to a single line of code.
|
||||
button, values = sg.Window('Compact 1-line form with column').LayoutAndRead(layout)
|
||||
|
||||
sg.Popup(button, values, line_width=200)
|
||||
|
||||
def PersistentForm():
|
||||
"""
|
||||
Persistent Form With Text Element Updates
|
||||
This simple program keep a form open, taking input values until the user terminates the program using the "X" button.
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
|
||||
window = sg.Window('Math')
|
||||
|
||||
output = sg.Txt('', size=(8,1))
|
||||
|
||||
layout = [ [sg.Txt('Enter values to calculate')],
|
||||
[sg.In(size=(8,1), key='numerator')],
|
||||
[sg.Txt('_' * 10)],
|
||||
[sg.In(size=(8,1), key='denominator')],
|
||||
[output],
|
||||
[sg.ReadButton('Calculate', bind_return_key=True)]]
|
||||
|
||||
window.Layout(layout)
|
||||
|
||||
while True:
|
||||
button, values = window.Read()
|
||||
|
||||
if button is not None:
|
||||
try:
|
||||
numerator = float(values['numerator'])
|
||||
denominator = float(values['denominator'])
|
||||
calc = numerator / denominator
|
||||
except:
|
||||
calc = 'Invalid'
|
||||
|
||||
output.Update(calc)
|
||||
else:
|
||||
break
|
||||
|
||||
def CanvasWidget():
|
||||
"""
|
||||
tkinter Canvas Widget
|
||||
The Canvas Element is one of the few tkinter objects that are directly accessible. The tkinter Canvas widget itself can be retrieved from a Canvas Element like this:
|
||||
"""
|
||||
|
||||
import PySimpleGUI as gui
|
||||
|
||||
canvas = gui.Canvas(size=(100,100), background_color='red')
|
||||
|
||||
layout = [
|
||||
[canvas],
|
||||
[gui.T('Change circle color to:'), gui.ReadButton('Red'), gui.ReadButton('Blue')]
|
||||
]
|
||||
|
||||
window = gui.Window('Canvas test', grab_anywhere=True)
|
||||
window.Layout(layout)
|
||||
window.ReadNonBlocking()
|
||||
|
||||
cir = canvas.TKCanvas.create_oval(50, 50, 100, 100)
|
||||
|
||||
while True:
|
||||
button, values = window.Read()
|
||||
if button is None:
|
||||
break
|
||||
if button is 'Blue':
|
||||
canvas.TKCanvas.itemconfig(cir, fill = "Blue")
|
||||
elif button is 'Red':
|
||||
canvas.TKCanvas.itemconfig(cir, fill = "Red")
|
||||
|
||||
def InputElementUpdate():
|
||||
"""
|
||||
Input Element Update
|
||||
This Recipe implements a Raspberry Pi touchscreen based keypad entry. As the digits are entered using the buttons, the Input Element above it is updated with the input digits. There are a number of features used in this Recipe including: Default Element Size auto_size_buttons ReadButton Dictionary Return values Update of Elements in form (Input, Text) do_not_clear of Input Elements
|
||||
"""
|
||||
import PySimpleGUI as g
|
||||
|
||||
# Demonstrates a number of PySimpleGUI features including:
|
||||
# Default element size
|
||||
# auto_size_buttons
|
||||
# ReadButton
|
||||
# Dictionary return values
|
||||
# Update of elements in form (Text, Input)
|
||||
# do_not_clear of Input elements
|
||||
|
||||
layout = [[g.Text('Enter Your Passcode')],
|
||||
[g.Input(size=(10, 1), do_not_clear=True, key='input')],
|
||||
[g.ReadButton('1'), g.ReadButton('2'), g.ReadButton('3')],
|
||||
[g.ReadButton('4'), g.ReadButton('5'), g.ReadButton('6')],
|
||||
[g.ReadButton('7'), g.ReadButton('8'), g.ReadButton('9')],
|
||||
[g.ReadButton('Submit'), g.ReadButton('0'), g.ReadButton('Clear')],
|
||||
[ g.Text('', size=(15, 1), font=('Helvetica', 18), text_color='red', key='output')],
|
||||
]
|
||||
|
||||
window = g.Window('Keypad', default_element_size=(5, 2), auto_size_buttons=False)
|
||||
window.Layout(layout)
|
||||
|
||||
# Loop forever reading the form's values, updating the Input field
|
||||
keys_entered = ''
|
||||
while True:
|
||||
button, values = window.Read() # read the form
|
||||
if button is None: # if the X button clicked, just exit
|
||||
break
|
||||
if button is 'Clear': # clear keys if clear button
|
||||
keys_entered = ''
|
||||
elif button in '1234567890':
|
||||
keys_entered = values['input'] # get what's been entered so far
|
||||
keys_entered += button # add the new digit
|
||||
elif button is 'Submit':
|
||||
keys_entered = values['input']
|
||||
window.FindElement('output').Update(keys_entered) # output the final string
|
||||
|
||||
window.FindElement('input').Update(keys_entered) # change the form to reflect current key string
|
||||
|
||||
|
||||
def TableSimulation():
|
||||
"""
|
||||
Display data in a table format
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
sg.ChangeLookAndFeel('Dark1')
|
||||
|
||||
layout = [[sg.T('Table Test')]]
|
||||
|
||||
for i in range(20):
|
||||
layout.append([sg.T('{} {}'.format(i,j), size=(4, 1), background_color='black', pad=(1, 1)) for j in range(10)])
|
||||
|
||||
sg.Window('Table').LayoutAndRead(layout)
|
||||
|
||||
|
||||
def TightLayout():
|
||||
"""
|
||||
Turn off padding in order to get a really tight looking layout.
|
||||
"""
|
||||
import PySimpleGUI as sg
|
||||
|
||||
sg.ChangeLookAndFeel('Dark')
|
||||
sg.SetOptions(element_padding=(0, 0))
|
||||
layout = [[sg.T('User:', pad=((3, 0), 0)), sg.OptionMenu(values=('User 1', 'User 2'), size=(20, 1)),
|
||||
sg.T('0', size=(8, 1))],
|
||||
[sg.T('Customer:', pad=((3, 0), 0)), sg.OptionMenu(values=('Customer 1', 'Customer 2'), size=(20, 1)),
|
||||
sg.T('1', size=(8, 1))],
|
||||
[sg.T('Notes:', pad=((3, 0), 0)), sg.In(size=(44, 1), background_color='white', text_color='black')],
|
||||
[sg.ReadButton('Start', button_color=('white', 'black')),
|
||||
sg.ReadButton('Stop', button_color=('white', 'black')),
|
||||
sg.ReadButton('Reset', button_color=('white', '#9B0023')),
|
||||
sg.ReadButton('Submit', button_color=('white', 'springgreen4')),
|
||||
sg.Button('Exit', button_color=('white', '#00406B')),
|
||||
]
|
||||
]
|
||||
|
||||
window = sg.Window("Time Tracker", default_element_size=(12, 1), text_justification='r', auto_size_text=False,
|
||||
auto_size_buttons=False, no_titlebar=True,
|
||||
default_button_element_size=(12, 1))
|
||||
window.Layout(layout)
|
||||
while True:
|
||||
button, values = window.Read()
|
||||
if button is None or button == 'Exit':
|
||||
return
|
||||
|
||||
# -------------------------------- GUI Starts Here -------------------------------#
|
||||
# fig = your figure you want to display. Assumption is that 'fig' holds the #
|
||||
# information to display. #
|
||||
# --------------------------------------------------------------------------------#
|
||||
|
||||
|
||||
import PySimpleGUI as sg
|
||||
|
||||
fig_dict = {'Simple Data Entry':SimpleDataEntry, 'Simple Entry Return Data as Dict':SimpleReturnAsDict, 'File Browse' : FileBrowse,
|
||||
'GUI Add On':GUIAddOn, 'Compare 2 Files':Compare2Files, 'All Widgets With Context Manager':AllWidgetsWithContext, 'All Widgets No Context Manager':AllWidgetsNoContext,
|
||||
'Non-Blocking With Updates':NonBlockingWithUpdates, 'Non-Bocking With Context Manager':NonBlockingWithContext, 'Callback Simulation':CallbackSimulation,
|
||||
'Realtime Buttons':RealtimeButtons, 'Easy Progress Meter':EasyProgressMeter, 'Tabbed Form':TabbedForm, 'Media Player':MediaPlayer, 'Script Launcher':ScriptLauncher,
|
||||
'Machine Learning':MachineLearning, 'Custom Progress Meter':CustromProgressMeter, 'One Line GUI':OneLineGUI, 'Multiple Columns':MultipleColumns,
|
||||
'Persistent Form':PersistentForm, 'Canvas Widget':CanvasWidget, 'Input Element Update':InputElementUpdate,
|
||||
'Table Simulation':TableSimulation, 'Tight Layout':TightLayout}
|
||||
|
||||
|
||||
# define the form layout
|
||||
listbox_values = [key for key in fig_dict.keys()]
|
||||
|
||||
while True:
|
||||
sg.ChangeLookAndFeel('Dark')
|
||||
# sg.SetOptions(element_padding=(0,0))
|
||||
|
||||
col_listbox = [[sg.Listbox(values=listbox_values, size=(max(len(x) for x in listbox_values),min(len(listbox_values), 20)), change_submits=False, key='func')],
|
||||
[sg.ReadButton('Run', pad=(0,0)), sg.ReadButton('Show Code', button_color=('white', 'gray25'), pad=(0,0)), sg.Exit(button_color=('white', 'firebrick4'), pad=(0,0))]]
|
||||
|
||||
layout = [[sg.Text('PySimpleGUI Coookbook', font=('current 18'))],
|
||||
[sg.Column(col_listbox), sg.Multiline(size=(50,min(len(listbox_values), 20)), do_not_clear=True, key='multi')],
|
||||
]
|
||||
|
||||
# create the form and show it without the plot
|
||||
# window.Layout(layout)
|
||||
|
||||
window = sg.Window('Demo Application - Embedding Matplotlib In PySimpleGUI', default_button_element_size=(9,1),auto_size_buttons=False, grab_anywhere=False)
|
||||
window.Layout(layout)
|
||||
# show it all again and get buttons
|
||||
while True:
|
||||
button, values = window.Read()
|
||||
|
||||
if button is None or button == 'Exit':
|
||||
exit(69)
|
||||
try:
|
||||
choice = values['func'][0]
|
||||
func = fig_dict[choice]
|
||||
except:
|
||||
continue
|
||||
|
||||
if button == 'Show Code' and values['multi']:
|
||||
window.FindElement('multi').Update(inspect.getsource(func))
|
||||
elif button is 'Run' and values['func']:
|
||||
# sg.ChangeLookAndFeel('SystemDefault')
|
||||
window.CloseNonBlocking()
|
||||
func()
|
||||
break
|
||||
else:
|
||||
print('ILLEGAL values')
|
||||
break
|
||||
|
|
@ -1,4 +1,14 @@
|
|||
# DESIGN PATTERN 1 - Simple Window
|
||||
"""
|
||||
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 PySimpleGUI as sg
|
||||
|
||||
layout = [[ sg.Text('My layout') ]]
|
||||
|
@ -6,7 +16,10 @@ layout = [[ sg.Text('My layout') ]]
|
|||
window = sg.Window('My window').Layout(layout)
|
||||
button, value = window.Read()
|
||||
|
||||
# DESIGN PATTERN 2 - Persistent Window
|
||||
|
||||
# -------------------------------------#
|
||||
# DESIGN PATTERN 2 - Persistent Window #
|
||||
# -------------------------------------#
|
||||
import PySimpleGUI as sg
|
||||
|
||||
layout = [[ sg.Text('My layout') ]]
|
||||
|
@ -18,7 +31,9 @@ while True: # Event Loop
|
|||
if button is None:
|
||||
break
|
||||
|
||||
# DESIGN PATTERN 3 - Persistent Window with "early update" required
|
||||
# ------------------------------------------------------------------#
|
||||
# DESIGN PATTERN 3 - Persistent Window with "early update" required #
|
||||
# ------------------------------------------------------------------#
|
||||
import PySimpleGUI as sg
|
||||
|
||||
layout = [[ sg.Text('My layout') ]]
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
import subprocess
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
"""
|
||||
Demo_Toolbar - A floating toolbar with quick launcher
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import time
|
||||
import random
|
||||
import psutil
|
||||
from threading import Thread
|
||||
import PySimpleGUI as sg
|
||||
|
||||
|
||||
STEP_SIZE=3
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import psutil
|
||||
import time
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
import psutil
|
||||
|
||||
# ---------------- Create Form ----------------
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import time
|
||||
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
sg.ChangeLookAndFeel('Dark')
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import hashlib
|
||||
import os
|
||||
import PySimpleGUI as sg
|
||||
|
||||
|
||||
# ====____====____==== FUNCTION DeDuplicate_folder(path) ====____====____==== #
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
def Everything():
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
layout = [[sg.Text('Filename', )],
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
import PySimpleGUI as gg
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import time
|
||||
|
||||
def main():
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
layout = [
|
||||
[sg.Graph(canvas_size=(400, 400), graph_bottom_left=(0,0), graph_top_right=(400, 400), background_color='red', key='graph')],
|
||||
[sg.T('Change circle color to:'), sg.ReadButton('Red'), sg.ReadButton('Blue'), sg.ReadButton('Move')]
|
||||
]
|
||||
layout = [[sg.Graph(canvas_size=(400, 400), graph_bottom_left=(0,0), graph_top_right=(400, 400), background_color='red', key='graph')],
|
||||
[sg.T('Change circle color to:'), sg.ReadButton('Red'), sg.ReadButton('Blue'), sg.ReadButton('Move')]]
|
||||
|
||||
window = sg.Window('Graph test').Layout(layout).Finalize()
|
||||
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import ping
|
||||
from threading import Thread
|
||||
import time
|
||||
import PySimpleGUI as sg
|
||||
|
||||
|
||||
STEP_SIZE=1
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
import math
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import math
|
||||
|
||||
layout = [[sg.Graph(canvas_size=(400, 400), graph_bottom_left=(-105,-105), graph_top_right=(105,105), background_color='white', key='graph', tooltip='This is a cool graph!')],]
|
||||
|
||||
layout = [[sg.T('Example of Using Math with a Graph', justification='center', size=(40,1), relief=sg.RELIEF_RAISED)],
|
||||
[sg.Graph(canvas_size=(400, 400), graph_bottom_left=(-105,-105), graph_top_right=(105,105), background_color='white', key='graph', tooltip='This is a cool graph!')],]
|
||||
|
||||
window = sg.Window('Graph of Sine Function', grab_anywhere=True).Layout(layout).Finalize()
|
||||
graph = window.FindElement('graph')
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import time
|
||||
import random
|
||||
import PySimpleGUI as sg
|
||||
import sys
|
||||
|
||||
STEP_SIZE=1
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import subprocess
|
||||
|
||||
|
@ -30,7 +35,7 @@ def HowDoI():
|
|||
sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))]
|
||||
]
|
||||
|
||||
window = sg.Window('How Do I ??', default_element_size=(30, 2), icon=DEFAULT_ICON, font=('Helvetica',' 13'), default_button_element_size=(8,2), return_keyboard_events=True, no_titlebar=True)
|
||||
window = sg.Window('How Do I ??', default_element_size=(30, 2), icon=DEFAULT_ICON, font=('Helvetica',' 13'), default_button_element_size=(8,2), return_keyboard_events=True, no_titlebar=True, grab_anywhere=True)
|
||||
window.Layout(layout)
|
||||
# ---===--- Loop taking in user input and using it to query HowDoI --- #
|
||||
command_history = []
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import os
|
||||
from PIL import Image, ImageTk
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
# Recipe for getting keys, one at a time as they are released
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
layout = [[sg.Text("Hold down a key")],
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
# Demonstrates a number of PySimpleGUI features including:
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import os
|
||||
import PySimpleGUI as g
|
||||
import mido
|
||||
import time
|
||||
import sys
|
||||
|
@ -32,17 +37,17 @@ class PlayerGUI():
|
|||
|
||||
# ---------------------- DEFINION OF CHOOSE WHAT TO PLAY GUI ----------------------------
|
||||
|
||||
layout = [[g.Text('MIDI File Player', font=("Helvetica", 15), size=(20, 1), text_color='green')],
|
||||
[g.Text('File Selection', font=("Helvetica", 15), size=(20, 1))],
|
||||
[g.Text('Single File Playback', justification='right'), g.InputText(size=(65, 1), key='midifile'), g.FileBrowse(size=(10, 1), file_types=(("MIDI files", "*.mid"),))],
|
||||
[g.Text('Or Batch Play From This Folder', auto_size_text=False, justification='right'), g.InputText(size=(65, 1), key='folder'), g.FolderBrowse(size=(10, 1))],
|
||||
[g.Text('_' * 250, auto_size_text=False, size=(100, 1))],
|
||||
[g.Text('Choose MIDI Output Device', size=(22, 1)),
|
||||
g.Listbox(values=self.PortList, size=(30, len(self.PortList) + 1), key='device')],
|
||||
[g.Text('_' * 250, auto_size_text=False, size=(100, 1))],
|
||||
[g.SimpleButton('PLAY', size=(12, 2), button_color=('red', 'white'), font=("Helvetica", 15), bind_return_key=True), g.Text(' ' * 2, size=(4, 1)), g.Cancel(size=(8, 2), font=("Helvetica", 15))]]
|
||||
layout = [[sg.Text('MIDI File Player', font=("Helvetica", 15), size=(20, 1), text_color='green')],
|
||||
[sg.Text('File Selection', font=("Helvetica", 15), size=(20, 1))],
|
||||
[sg.Text('Single File Playback', justification='right'), sg.InputText(size=(65, 1), key='midifile'), sg.FileBrowse(size=(10, 1), file_types=(("MIDI files", "*.mid"),))],
|
||||
[sg.Text('Or Batch Play From This Folder', auto_size_text=False, justification='right'), sg.InputText(size=(65, 1), key='folder'), sg.FolderBrowse(size=(10, 1))],
|
||||
[sg.Text('_' * 250, auto_size_text=False, size=(100, 1))],
|
||||
[sg.Text('Choose MIDI Output Device', size=(22, 1)),
|
||||
sg.Listbox(values=self.PortList, size=(30, len(self.PortList) + 1), key='device')],
|
||||
[sg.Text('_' * 250, auto_size_text=False, size=(100, 1))],
|
||||
[sg.SimpleButton('PLAY', size=(12, 2), button_color=('red', 'white'), font=("Helvetica", 15), bind_return_key=True), sg.Text(' ' * 2, size=(4, 1)), sg.Cancel(size=(8, 2), font=("Helvetica", 15))]]
|
||||
|
||||
window = g.Window('MIDI File Player', auto_size_text=False, default_element_size=(30, 1), font=("Helvetica", 12)).Layout(layout)
|
||||
window = sg.Window('MIDI File Player', auto_size_text=False, default_element_size=(30, 1), font=("Helvetica", 12)).Layout(layout)
|
||||
self.Window = window
|
||||
return window.Read()
|
||||
|
||||
|
@ -55,23 +60,23 @@ class PlayerGUI():
|
|||
image_next = './ButtonGraphics/Next.png'
|
||||
image_exit = './ButtonGraphics/Exit.png'
|
||||
|
||||
self.TextElem = g.T('Song loading....', size=(70,5 + NumFiles), font=("Helvetica", 14), auto_size_text=False)
|
||||
self.SliderElem = g.Slider(range=(1,100), size=(50, 8), orientation='h', text_color='#f0f0f0')
|
||||
self.TextElem = sg.T('Song loading....', size=(70, 5 + NumFiles), font=("Helvetica", 14), auto_size_text=False)
|
||||
self.SliderElem = sg.Slider(range=(1, 100), size=(50, 8), orientation='h', text_color='#f0f0f0')
|
||||
layout = [
|
||||
[g.T('MIDI File Player', size=(30,1), font=("Helvetica", 25))],
|
||||
[sg.T('MIDI File Player', size=(30, 1), font=("Helvetica", 25))],
|
||||
[self.TextElem],
|
||||
[self.SliderElem],
|
||||
[g.ReadFormButton('PAUSE', button_color=g.TRANSPARENT_BUTTON,
|
||||
image_filename=image_pause, image_size=(50,50),image_subsample=2, border_width=0), g.T(' '),
|
||||
g.ReadFormButton('NEXT', button_color=g.TRANSPARENT_BUTTON,
|
||||
image_filename=image_next, image_size=(50,50),image_subsample=2, border_width=0), g.T(' '),
|
||||
g.ReadFormButton('Restart Song', button_color=g.TRANSPARENT_BUTTON,
|
||||
image_filename=image_restart, image_size=(50,50), image_subsample=2, border_width=0), g.T(' '),
|
||||
g.SimpleButton('EXIT', button_color=g.TRANSPARENT_BUTTON,
|
||||
[sg.ReadFormButton('PAUSE', button_color=sg.TRANSPARENT_BUTTON,
|
||||
image_filename=image_pause, image_size=(50,50), image_subsample=2, border_width=0), sg.T(' '),
|
||||
sg.ReadFormButton('NEXT', button_color=sg.TRANSPARENT_BUTTON,
|
||||
image_filename=image_next, image_size=(50,50), image_subsample=2, border_width=0), sg.T(' '),
|
||||
sg.ReadFormButton('Restart Song', button_color=sg.TRANSPARENT_BUTTON,
|
||||
image_filename=image_restart, image_size=(50,50), image_subsample=2, border_width=0), sg.T(' '),
|
||||
sg.SimpleButton('EXIT', button_color=sg.TRANSPARENT_BUTTON,
|
||||
image_filename=image_exit, image_size=(50,50), image_subsample=2, border_width=0, )]
|
||||
]
|
||||
|
||||
window = g.FlexForm('MIDI File Player', default_element_size=(30,1),font=("Helvetica", 25)).Layout(layout).Finalize()
|
||||
window = sg.FlexForm('MIDI File Player', default_element_size=(30, 1), font=("Helvetica", 25)).Layout(layout).Finalize()
|
||||
self.Window = window
|
||||
|
||||
|
||||
|
@ -118,12 +123,12 @@ def main():
|
|||
|
||||
button, values = pback.PlayerChooseSongGUI()
|
||||
if button != 'PLAY':
|
||||
g.PopupCancel('Cancelled...\nAutoclose in 2 sec...', auto_close=True, auto_close_duration=2)
|
||||
sg.PopupCancel('Cancelled...\nAutoclose in 2 sec...', auto_close=True, auto_close_duration=2)
|
||||
sys.exit(69)
|
||||
if values['device']:
|
||||
midi_port = values['device'][0]
|
||||
else:
|
||||
g.PopupCancel('No devices found\nAutoclose in 2 sec...', auto_close=True, auto_close_duration=2)
|
||||
sg.PopupCancel('No devices found\nAutoclose in 2 sec...', auto_close=True, auto_close_duration=2)
|
||||
|
||||
batch_folder = values['folder']
|
||||
midi_filename = values['midifile']
|
||||
|
@ -136,7 +141,7 @@ def main():
|
|||
filelist = [midi_filename,]
|
||||
filetitles = [os.path.basename(midi_filename),]
|
||||
else:
|
||||
g.PopupError('*** Error - No MIDI files specified ***')
|
||||
sg.PopupError('*** Error - No MIDI files specified ***')
|
||||
sys.exit(666)
|
||||
|
||||
# ------ LOOP THROUGH MULTIPLE FILES --------------------------------------------------------- #
|
||||
|
@ -160,7 +165,7 @@ def main():
|
|||
mid = mido.MidiFile(filename=midi_filename)
|
||||
except:
|
||||
print('****** Exception trying to play MidiFile filename = {}***************'.format(midi_filename))
|
||||
g.PopupError('Exception trying to play MIDI file:', midi_filename, 'Skipping file')
|
||||
sg.PopupError('Exception trying to play MIDI file:', midi_filename, 'Skipping file')
|
||||
continue
|
||||
|
||||
# Build list of data contained in MIDI File using only track 0
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
def MachineLearningGUI():
|
||||
sg.SetOptions(text_justification='right')
|
||||
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
import matplotlib
|
||||
matplotlib.use('TkAgg')
|
||||
from matplotlib.backends.backend_tkagg import FigureCanvasAgg
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
from random import randint
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
from random import randint
|
||||
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, FigureCanvasAgg
|
||||
from matplotlib.figure import Figure
|
||||
import matplotlib.backends.tkagg as tkagg
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
from random import randint
|
||||
import PySimpleGUI as sg
|
||||
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, FigureCanvasAgg
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import matplotlib
|
||||
matplotlib.use('TkAgg')
|
||||
|
@ -247,7 +252,7 @@ def PyplotLineStyles():
|
|||
|
||||
# For each line style, add a text annotation with a small offset from
|
||||
# the reference point (0 in Axes coords, y tick value in Data coords).
|
||||
reference_transwindow = blended_transform_factory(ax.transAxes, ax.transData)
|
||||
reference_transform = blended_transform_factory(ax.transAxes, ax.transData)
|
||||
for i, (name, linestyle) in enumerate(linestyles.items()):
|
||||
ax.annotate(str(linestyle), xy=(0.0, i), xycoords=reference_transform,
|
||||
xytext=(-6, -12), textcoords='offset points', color="blue",
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.backends.backend_tkagg import FigureCanvasAgg
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import matplotlib.pyplot as plt
|
||||
import ping
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
#
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
"""
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import time
|
||||
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import cv2 as cv
|
||||
from PIL import Image
|
||||
import tempfile
|
||||
import PySimpleGUI as sg
|
||||
import os
|
||||
from sys import exit as exit
|
||||
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import os
|
||||
from sys import exit as exit
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import hashlib
|
||||
from sys import exit as exit
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
import PySimpleGUI as rg
|
||||
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
# GUI for switching an LED on and off to GPIO14
|
||||
|
||||
# GPIO and time library:
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
# Robotics design pattern
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
from threading import Thread
|
||||
import time
|
||||
import PySimpleGUI as sg
|
||||
from sys import exit as exit
|
||||
|
||||
# !/usr/bin/env python3
|
||||
|
@ -215,7 +220,7 @@ import os, sys, socket, struct, select, time, signal
|
|||
|
||||
__description__ = 'A pure python ICMP ping implementation using raw sockets.'
|
||||
|
||||
if sys.platwindow == "win32":
|
||||
if sys.platform == "win32":
|
||||
# On Windows, the best timer is time.clock()
|
||||
default_timer = time.clock
|
||||
else:
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
import random
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import random
|
||||
import time
|
||||
from sys import exit as exit
|
||||
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
# Here, have some windows on me....
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
from time import sleep
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
from time import sleep
|
||||
from sys import exit as exit
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import glob
|
||||
import ntpath
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import sys
|
||||
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
"""
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
"""
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
import csv
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import csv
|
||||
import sys
|
||||
|
||||
def table_example():
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import csv
|
||||
import PySimpleGUI as sg
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import csv
|
||||
|
||||
|
||||
filename = sg.PopupGetFile('filename to open', no_window=True, file_types=(("CSV Files","*.csv"),))
|
||||
# --- populate table with file contents --- #
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import pandas as pd
|
||||
import PySimpleGUI as sg
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import pandas as pd
|
||||
|
||||
|
||||
def table_example():
|
||||
sg.SetOptions(auto_size_buttons=True)
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
import csv
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import csv
|
||||
|
||||
|
||||
def TableSimulation():
|
||||
"""
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
tab1_layout = [[sg.T('This is inside tab 1')]]
|
||||
|
@ -5,7 +10,7 @@ tab1_layout = [[sg.T('This is inside tab 1')]]
|
|||
tab2_layout = [[sg.T('This is inside tab 2')],
|
||||
[sg.In(key='in')]]
|
||||
|
||||
layout = [[sg.TabGroup([[sg.Tab('Tab 1', tab1_layout, tooltip='tip'), sg.Tab('Tab 2', tab2_layout)]], tooltip='TIP2')],
|
||||
layout = [[sg.TabGroup([[sg.Tab('Tab 1', tab1_layout), sg.Tab('Tab 2', tab2_layout)]])],
|
||||
[sg.RButton('Read')]]
|
||||
|
||||
window = sg.Window('My window with tabs', default_element_size=(12,1)).Layout(layout)
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
sg.ChangeLookAndFeel('GreenTan')
|
||||
tab2_layout = [[sg.T('This is inside tab 2')],
|
||||
[sg.T('Tabs can be anywhere now!')]
|
||||
]
|
||||
[sg.T('Tabs can be anywhere now!')]]
|
||||
|
||||
tab1_layout = [[sg.T('Type something here and click button'), sg.In(key='in')]]
|
||||
|
||||
|
@ -21,8 +26,7 @@ layout = [[sg.T('My Window!')], [sg.Frame('A Frame', layout=
|
|||
[[sg.TabGroup([[sg.Tab('Tab 1', tab1_layout), sg.Tab('Tab 2', tab2_layout)]]), sg.TabGroup([[sg.Tab('Tab3', tab3_layout), sg.Tab('Tab 4', tab4_layout)]])]])],
|
||||
[sg.T('This text is on a row with a column'),sg.Column(layout=[[sg.T('In a column')],
|
||||
[sg.TabGroup([[sg.Tab('Tab 5', tab5_layout), sg.Tab('Tab 6', tab6_layout)]])],
|
||||
[sg.RButton('Click me')]])],
|
||||
]
|
||||
[sg.RButton('Click me')]])],]
|
||||
|
||||
window = sg.Window('My window with tabs', default_element_size=(12,1)).Layout(layout).Finalize()
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
#choose one of these are your starting point
|
||||
|
||||
# ---------------------------------#
|
||||
# DESIGN PATTERN 1 - Simple Window #
|
||||
# ---------------------------------#
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
layout = [[ sg.Text('My layout') ]]
|
||||
|
||||
window = sg.Window('My window').Layout(layout)
|
||||
button, value = window.Read()
|
||||
|
||||
|
||||
# -------------------------------------#
|
||||
# DESIGN PATTERN 2 - Persistent Window #
|
||||
# -------------------------------------#
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
|
||||
layout = [[ sg.Text('My layout') ]]
|
||||
|
||||
window = sg.Window('My new window').Layout(layout)
|
||||
|
||||
while True: # Event Loop
|
||||
button, value = window.Read()
|
||||
if button is None:
|
||||
break
|
|
@ -1,3 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
import PySimpleGUI27 as sg
|
||||
else:
|
||||
import PySimpleGUI as sg
|
||||
import subprocess
|
||||
|
||||
|
|
Loading…
Reference in New Issue