Removed F-string

Oops, and f-string creaped in
This commit is contained in:
MikeTheWatchGuy 2018-07-24 12:20:34 -04:00
parent e2f9f5c834
commit 8e329e7690
1 changed files with 66 additions and 68 deletions

View File

@ -1,22 +1,20 @@
import time import time
from random import randint from random import randint
import random import PySimpleGUI as sg
import string
import PySimpleGUI as SG
# A simple blocking form. Your best starter-form # A simple blocking form. Your best starter-form
def SourceDestFolders(): def SourceDestFolders():
with SG.FlexForm('Demo Source / Destination Folders', auto_size_text=True) as form: with sg.FlexForm('Demo Source / Destination Folders', auto_size_text=True) as form:
form_rows = [[SG.Text('Enter the Source and Destination folders')], form_rows = [[sg.Text('Enter the Source and Destination folders')],
[SG.Text('Source Folder', size=(15, 1), auto_size_text=False, justification='right'), SG.InputText('Source')], [sg.Text('Source Folder', size=(15, 1), auto_size_text=False, justification='right'), sg.InputText('Source')],
[SG.Text('Destination Folder', size=(15, 1), auto_size_text=False, justification='right'), SG.InputText('Dest'), SG.FolderBrowse()], [sg.Text('Destination Folder', size=(15, 1), auto_size_text=False, justification='right'), sg.InputText('Dest'), sg.FolderBrowse()],
[SG.Submit(), SG.Cancel()]] [sg.Submit(), sg.Cancel()]]
button, (source, dest) = form.LayoutAndRead(form_rows) button, (source, dest) = form.LayoutAndRead(form_rows)
if button == 'Submit': if button == 'Submit':
SG.MsgBox('Submitted', 'The user entered source:', source, 'Destination folder:', dest, 'Using button', button) sg.MsgBox('Submitted', 'The user entered source:', source, 'Destination folder:', dest, 'Using button', button)
else: else:
SG.MsgBoxError('Cancelled', 'User Cancelled') sg.MsgBoxError('Cancelled', 'User Cancelled')
# YOUR BEST STARTING POINT # YOUR BEST STARTING POINT
# This is a form showing you all of the basic Elements (widgets) # This is a form showing you all of the basic Elements (widgets)
@ -25,71 +23,71 @@ def SourceDestFolders():
# Use this especially if you are runningm multi-threaded # Use this especially if you are runningm multi-threaded
# Where you free up resources is really important to tkinter # Where you free up resources is really important to tkinter
def Everything(): def Everything():
with SG.FlexForm('Everything bagel', auto_size_text=True, default_element_size=(40, 1)) as form: with sg.FlexForm('Everything bagel', auto_size_text=True, default_element_size=(40, 1)) as form:
layout = [ layout = [
[SG.Text('All graphic widgets in one form!', size=(30, 1), font=("Helvetica", 25), text_color='blue')], [sg.Text('All graphic widgets in one form!', size=(30, 1), font=("Helvetica", 25), text_color='blue')],
[SG.Text('Here is some text.... and a place to enter text')], [sg.Text('Here is some text.... and a place to enter text')],
[SG.InputText()], [sg.InputText()],
[SG.Checkbox('My first checkbox!'), SG.Checkbox('My second checkbox!', default=True)], [sg.Checkbox('My first checkbox!'), sg.Checkbox('My second checkbox!', default=True)],
[SG.Radio('My first Radio! ', "RADIO1", default=True), SG.Radio('My second Radio!', "RADIO1")], [sg.Radio('My first Radio! ', "RADIO1", default=True), sg.Radio('My second Radio!', "RADIO1")],
[SG.Multiline(default_text='This is the default Text shoulsd you decide not to type anything', [sg.Multiline(default_text='This is the default Text shoulsd you decide not to type anything',
scale=(2, 10))], scale=(2, 10))],
[SG.InputCombo(['Combobox 1', 'Combobox 2'], size=(20, 3)), [sg.InputCombo(['Combobox 1', 'Combobox 2'], size=(20, 3)),
SG.Slider(range=(1, 100), orientation='h', size=(35, 20), default_value=85)], sg.Slider(range=(1, 100), orientation='h', size=(35, 20), default_value=85)],
[SG.Listbox(values=['Listbox 1', 'Listbox 2', 'Listbox 3'], size=(30, 6)), [sg.Listbox(values=['Listbox 1', 'Listbox 2', 'Listbox 3'], size=(30, 6)),
SG.Slider(range=(1, 100), orientation='v', size=(10, 20), default_value=25), sg.Slider(range=(1, 100), orientation='v', size=(10, 20), default_value=25),
SG.Slider(range=(1, 100), orientation='v', size=(10, 20), default_value=75), sg.Slider(range=(1, 100), orientation='v', size=(10, 20), default_value=75),
SG.Slider(range=(1, 100), orientation='v', size=(10, 20), default_value=10)], sg.Slider(range=(1, 100), orientation='v', size=(10, 20), default_value=10)],
[SG.Text('_' * 100, size=(70, 1))], [sg.Text('_' * 100, size=(70, 1))],
[SG.Text('Choose Source and Destination Folders', size=(35, 1))], [sg.Text('Choose Source and Destination Folders', size=(35, 1))],
[SG.Text('Source Folder', size=(15, 1), auto_size_text=False, justification='right'), SG.InputText('Source'), SG.FolderBrowse()], [sg.Text('Source Folder', size=(15, 1), auto_size_text=False, justification='right'), sg.InputText('Source'), sg.FolderBrowse()],
[SG.Text('Destination Folder', size=(15, 1), auto_size_text=False, justification='right'), SG.InputText('Dest'), [sg.Text('Destination Folder', size=(15, 1), auto_size_text=False, justification='right'), sg.InputText('Dest'),
SG.FolderBrowse()], sg.FolderBrowse()],
[SG.Submit(), SG.Cancel(), SG.SimpleButton('Customized', button_color=('white', 'green'))] [sg.Submit(), sg.Cancel(), sg.SimpleButton('Customized', button_color=('white', 'green'))]
] ]
button, values = form.LayoutAndRead(layout) button, values = form.LayoutAndRead(layout)
SG.MsgBox('Title', 'Typical message box', 'The results of the form are a lot of data! Get ready... ', 'The button clicked was "{}"'.format(button), 'The values are', values) sg.MsgBox('Title', 'Typical message box', 'The results of the form are a lot of data! Get ready... ', 'The button clicked was "{}"'.format(button), 'The values are', values)
# Should you decide not to use a context manager, then try this form as your starting point # Should you decide not to use a context manager, then try this form as your starting point
# Be aware that tkinter, which this is based on, is picky about who frees up resources, especially if # Be aware that tkinter, which this is based on, is picky about who frees up resources, especially if
# you are running multithreaded # you are running multithreaded
def Everything_NoContextManager(): def Everything_NoContextManager():
form = SG.FlexForm('Everything bagel', auto_size_text=True, default_element_size=(40, 1)) form = sg.FlexForm('Everything bagel', auto_size_text=True, default_element_size=(40, 1))
layout = [[SG.Text('All graphic widgets in one form!', size=(30, 1), font=("Helvetica", 25), text_color='blue')], layout = [[sg.Text('All graphic widgets in one form!', size=(30, 1), font=("Helvetica", 25), text_color='blue')],
[SG.Text('Here is some text.... and a place to enter text')], [sg.Text('Here is some text.... and a place to enter text')],
[SG.InputText()], [sg.InputText()],
[SG.Checkbox('My first checkbox!'), SG.Checkbox('My second checkbox!', default=True)], [sg.Checkbox('My first checkbox!'), sg.Checkbox('My second checkbox!', default=True)],
[SG.Radio('My first Radio! ', "RADIO1", default=True), SG.Radio('My second Radio!', "RADIO1")], [sg.Radio('My first Radio! ', "RADIO1", default=True), sg.Radio('My second Radio!', "RADIO1")],
[SG.Multiline(default_text='This is the default Text shoulsd you decide not to type anything', scale=(2, 10))], [sg.Multiline(default_text='This is the default Text shoulsd you decide not to type anything', scale=(2, 10))],
[SG.InputCombo(['Combobox 1', 'Combobox 2'], size=(20, 3)), SG.Slider(range=(1,100), orientation='h', size=(35,20), default_value=85)], [sg.InputCombo(['Combobox 1', 'Combobox 2'], size=(20, 3)), sg.Slider(range=(1, 100), orientation='h', size=(35, 20), default_value=85)],
[SG.Listbox(values=['Listbox 1','Listbox 2', 'Listbox 3'], size=(30,6)), [sg.Listbox(values=['Listbox 1', 'Listbox 2', 'Listbox 3'], size=(30, 6)),
SG.Slider(range=(1,100), orientation='v', size=(10, 20), default_value=25), sg.Slider(range=(1, 100), orientation='v', size=(10, 20), default_value=25),
SG.Slider(range=(1, 100), orientation='v', size=(10, 20), default_value=75), sg.Slider(range=(1, 100), orientation='v', size=(10, 20), default_value=75),
SG.Slider(range=(1, 100), orientation='v', size=(10, 20), default_value=10)], sg.Slider(range=(1, 100), orientation='v', size=(10, 20), default_value=10)],
[SG.Text('_' * 100, size=(70, 1))], [sg.Text('_' * 100, size=(70, 1))],
[SG.Text('Choose Source and Destination Folders', size=(35, 1), text_color='red')], [sg.Text('Choose Source and Destination Folders', size=(35, 1), text_color='red')],
[SG.Text('Source Folder', size=(15, 1), auto_size_text=False, justification='right'), SG.InputText('Source'), SG.FolderBrowse()], [sg.Text('Source Folder', size=(15, 1), auto_size_text=False, justification='right'), sg.InputText('Source'), sg.FolderBrowse()],
[SG.Text('Destination Folder', size=(15, 1), auto_size_text=False, justification='right'), SG.InputText('Dest'), SG.FolderBrowse()], [sg.Text('Destination Folder', size=(15, 1), auto_size_text=False, justification='right'), sg.InputText('Dest'), sg.FolderBrowse()],
[SG.Submit(), SG.Cancel(), SG.SimpleButton('Customized', button_color=('white', 'green'))]] [sg.Submit(), sg.Cancel(), sg.SimpleButton('Customized', button_color=('white', 'green'))]]
button, values = form.LayoutAndRead(layout) button, values = form.LayoutAndRead(layout)
del(form) del(form)
SG.MsgBox('Title', 'Typical message box', 'Here are the restults! There is one entry per input field ', 'The button clicked was "{}"'.format(button), 'The values are', values) sg.MsgBox('Title', 'Typical message box', 'Here are the restults! There is one entry per input field ', 'The button clicked was "{}"'.format(button), 'The values are', values)
def ProgressMeter(): def ProgressMeter():
for i in range(1,10000): for i in range(1,10000):
if not SG.EasyProgressMeter('My Meter', i+1, 10000): break if not sg.EasyProgressMeter('My Meter', i + 1, 10000): break
# SG.Print(i) # SG.Print(i)
# Blocking form that doesn't close # Blocking form that doesn't close
def ChatBot(): def ChatBot():
with SG.FlexForm('Chat Window', auto_size_text=True, default_element_size=(30, 2)) as form: with sg.FlexForm('Chat Window', auto_size_text=True, default_element_size=(30, 2)) as form:
layout = [[(SG.Text('This is where standard out is being routed', size=[40, 1]))], layout = [[(sg.Text('This is where standard out is being routed', size=[40, 1]))],
[SG.Output(size=(80, 20))], [sg.Output(size=(80, 20))],
[SG.Multiline(size=(70, 5), enter_submits=True), SG.ReadFormButton('SEND', button_color=(SG.YELLOWS[0], SG.BLUES[0])), SG.SimpleButton('EXIT', button_color=(SG.YELLOWS[0], SG.GREENS[0]))]] [sg.Multiline(size=(70, 5), enter_submits=True), sg.ReadFormButton('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0])), sg.SimpleButton('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))]]
# notice this is NOT the usual LayoutAndRead call because you don't yet want to read the form # notice this is NOT the usual LayoutAndRead call because you don't yet want to read the form
# if you call LayoutAndRead from here, then you will miss the first button click # if you call LayoutAndRead from here, then you will miss the first button click
form.Layout(layout) form.Layout(layout)
@ -106,15 +104,15 @@ def ChatBot():
# form within the 'with' block. If your read occurs far away in your code from the form creation # form within the 'with' block. If your read occurs far away in your code from the form creation
# then you will want to use the NonBlockingPeriodicUpdateForm example # then you will want to use the NonBlockingPeriodicUpdateForm example
def NonBlockingPeriodicUpdateForm_ContextManager(): def NonBlockingPeriodicUpdateForm_ContextManager():
with SG.FlexForm('Running Timer', auto_size_text=True) as form: with sg.FlexForm('Running Timer', auto_size_text=True) as form:
text_element = SG.Text('',size=(10,2), font=('Helvetica', 20), text_color='red', justification='center') text_element = sg.Text('', size=(10, 2), font=('Helvetica', 20), text_color='red', justification='center')
layout = [[SG.Text('Non blocking GUI with updates', justification='center')], layout = [[sg.Text('Non blocking GUI with updates', justification='center')],
[text_element], [text_element],
[SG.T(' '*15), SG.Quit()]] [sg.T(' ' * 15), sg.Quit()]]
form.LayoutAndRead(layout, non_blocking=True) form.LayoutAndRead(layout, non_blocking=True)
for i in range(1,500): for i in range(1,500):
text_element.Update('{:02d}:{:02d}.{:02d}'.format(*divmod(int(i/100), 60), i%100)) text_element.Update('{:02d}:{:02d}.{:02d}'.format((i // 100) // 60, (i // 100) % 60, i % 100))
button, values = form.ReadNonBlocking() button, values = form.ReadNonBlocking()
if values is None or button == 'Quit': # if user closed the window using X if values is None or button == 'Quit': # if user closed the window using X
break break
@ -127,15 +125,15 @@ def NonBlockingPeriodicUpdateForm_ContextManager():
# from the form creation (call to LayoutAndRead) # from the form creation (call to LayoutAndRead)
def NonBlockingPeriodicUpdateForm(): def NonBlockingPeriodicUpdateForm():
# Show a form that's a running counter # Show a form that's a running counter
form = SG.FlexForm('Running Timer', auto_size_text=True) form = sg.FlexForm('Running Timer', auto_size_text=True)
text_element = SG.Text('',size=(10,2), font=('Helvetica', 20), justification='center') text_element = sg.Text('', size=(10, 2), font=('Helvetica', 20), justification='center')
form_rows = [[SG.Text('Non blocking GUI with updates')], form_rows = [[sg.Text('Non blocking GUI with updates')],
[text_element], [text_element],
[SG.T(' ' * 15), SG.Quit()]] [sg.T(' ' * 15), sg.Quit()]]
form.LayoutAndRead(form_rows, non_blocking=True) form.LayoutAndRead(form_rows, non_blocking=True)
for i in range(1,50000): for i in range(1,50000):
text_element.Update(f'{(i//100)//60:02d}:{(i//100)%60:02d}.{i%100:02d}') text_element.Update('{:02d}:{:02d}.{:02d}'.format((i//100)//60, (i//100)%60, i%100))
button, values = form.ReadNonBlocking() button, values = form.ReadNonBlocking()
if values is None or button == 'Quit': # if user closed the window using X or clicked Quit button if values is None or button == 'Quit': # if user closed the window using X or clicked Quit button
break break
@ -148,22 +146,22 @@ def NonBlockingPeriodicUpdateForm():
def DebugTest(): def DebugTest():
# SG.Print('How about we print a bunch of random numbers?', , size=(90,40)) # SG.Print('How about we print a bunch of random numbers?', , size=(90,40))
for i in range (1,300): for i in range (1,300):
SG.Print(i, randint(1, 1000), end='', sep='-') sg.Print(i, randint(1, 1000), end='', sep='-')
def main(): def main():
# SG.SetOptions(border_width=1, font=("Helvetica", 10), button_color=('white', SG.BLUES[0]), slider_border_width=1) # SG.SetOptions(border_width=1, font=("Helvetica", 10), button_color=('white', SG.BLUES[0]), slider_border_width=1)
Everything_NoContextManager()
Everything()
NonBlockingPeriodicUpdateForm_ContextManager() NonBlockingPeriodicUpdateForm_ContextManager()
NonBlockingPeriodicUpdateForm() NonBlockingPeriodicUpdateForm()
Everything_NoContextManager()
Everything()
ChatBot() ChatBot()
Everything() Everything()
ProgressMeter() ProgressMeter()
SourceDestFolders() SourceDestFolders()
ChatBot() ChatBot()
DebugTest() DebugTest()
SG.MsgBox('Done with all recipes') sg.MsgBox('Done with all recipes')
if __name__ == '__main__': if __name__ == '__main__':
main() main()