Renamed ALL oprtional parameters

Switched from CamelCase to all_lower_case
This commit is contained in:
MikeTheWatchGuy 2018-07-16 14:52:16 -04:00
parent c3ee62f29f
commit 0ec43ac112
7 changed files with 531 additions and 534 deletions

View File

@ -51,7 +51,7 @@ def compute_sha256_hash_for_file(filename):
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
def HashManuallyBuiltGUI(): def HashManuallyBuiltGUI():
# ------- Form design ------- # # ------- Form design ------- #
with SG.FlexForm('SHA-1 & 256 Hash', AutoSizeText=True) as form: with SG.FlexForm('SHA-1 & 256 Hash', auto_size_text=True) as form:
form_rows = [[SG.Text('SHA-1 and SHA-256 Hashes for the file')], form_rows = [[SG.Text('SHA-1 and SHA-256 Hashes for the file')],
[SG.InputText(), SG.FileBrowse()], [SG.InputText(), SG.FileBrowse()],
[SG.Submit(), SG.Cancel()]] [SG.Submit(), SG.Cancel()]]
@ -61,14 +61,14 @@ def HashManuallyBuiltGUI():
if source_filename != '': if source_filename != '':
hash_sha1 = compute_sha1_hash_for_file(source_filename).upper() hash_sha1 = compute_sha1_hash_for_file(source_filename).upper()
hash_sha256 = compute_sha256_hash_for_file(source_filename).upper() hash_sha256 = compute_sha256_hash_for_file(source_filename).upper()
SG.MsgBox( 'Display A Hash in PySimpleGUI', 'The SHA-1 Hash for the file\n', source_filename, hash_sha1, 'SHA-256 is', hash_sha256, LineWidth=75) SG.MsgBox( 'Display A Hash in PySimpleGUI', 'The SHA-1 Hash for the file\n', source_filename, hash_sha1, 'SHA-256 is', hash_sha256, line_width=75)
else: SG.MsgBoxError('Display A Hash in PySimpleGUI', 'Illegal filename') else: SG.MsgBoxError('Display A Hash in PySimpleGUI', 'Illegal filename')
else: else:
SG.MsgBoxError('Display A Hash in PySimpleGUI', '* Cancelled *') SG.MsgBoxError('Display A Hash in PySimpleGUI', '* Cancelled *')
def HashManuallyBuiltGUINonContext(): def HashManuallyBuiltGUINonContext():
# ------- Form design ------- # # ------- Form design ------- #
form = SG.FlexForm('SHA-1 & 256 Hash', AutoSizeText=True) form = SG.FlexForm('SHA-1 & 256 Hash', auto_size_text=True)
form_rows = [[SG.Text('SHA-1 and SHA-256 Hashes for the file')], form_rows = [[SG.Text('SHA-1 and SHA-256 Hashes for the file')],
[SG.InputText(), SG.FileBrowse()], [SG.InputText(), SG.FileBrowse()],
[SG.Submit(), SG.Cancel()]] [SG.Submit(), SG.Cancel()]]
@ -78,7 +78,7 @@ def HashManuallyBuiltGUINonContext():
if source_filename != '': if source_filename != '':
hash_sha1 = compute_sha1_hash_for_file(source_filename).upper() hash_sha1 = compute_sha1_hash_for_file(source_filename).upper()
hash_sha256 = compute_sha256_hash_for_file(source_filename).upper() hash_sha256 = compute_sha256_hash_for_file(source_filename).upper()
SG.MsgBox( 'Display A Hash in PySimpleGUI', 'The SHA-1 Hash for the file\n', source_filename, hash_sha1, 'SHA-256 is', hash_sha256, LineWidth=75) SG.MsgBox( 'Display A Hash in PySimpleGUI', 'The SHA-1 Hash for the file\n', source_filename, hash_sha1, 'SHA-256 is', hash_sha256, line_width=75)
else: SG.MsgBoxError('Display A Hash in PySimpleGUI', 'Illegal filename') else: SG.MsgBoxError('Display A Hash in PySimpleGUI', 'Illegal filename')
else: else:
SG.MsgBoxError('Display A Hash in PySimpleGUI', '* Cancelled *') SG.MsgBoxError('Display A Hash in PySimpleGUI', '* Cancelled *')

View File

@ -1,6 +1,5 @@
import hashlib import hashlib
import os import os
import win32clipboard
import PySimpleGUI as gg import PySimpleGUI as gg
@ -10,15 +9,13 @@ import PySimpleGUI as gg
def FindDuplicatesFilesInFolder(path): def FindDuplicatesFilesInFolder(path):
shatab = [] shatab = []
total = 0 total = 0
small = (1024)
small_count, dup_count, error_count = 0,0,0 small_count, dup_count, error_count = 0,0,0
pngdir = path pngdir = path
if not os.path.exists(path): if not os.path.exists(path):
gg.MsgBox('De-Dupe', '** Folder doesn\'t exist***', path) gg.MsgBox('Duplicate Finder', '** Folder doesn\'t exist***', path)
return return
pngfiles = os.listdir(pngdir) pngfiles = os.listdir(pngdir)
total_files = len(pngfiles) total_files = len(pngfiles)
not_cancelled = True
for idx, f in enumerate(pngfiles): for idx, f in enumerate(pngfiles):
if not gg.EasyProgressMeter('Counting Duplicates', idx+1, total_files, 'Counting Duplicate Files'): if not gg.EasyProgressMeter('Counting Duplicates', idx+1, total_files, 'Counting Duplicate Files'):
break break
@ -32,6 +29,7 @@ def FindDuplicatesFilesInFolder(path):
m.update(x) m.update(x)
f_sha = m.digest() f_sha = m.digest()
if f_sha in shatab: if f_sha in shatab:
# uncomment next line to remove duplicate files
# os.remove(fname) # os.remove(fname)
dup_count += 1 dup_count += 1
continue continue
@ -50,9 +48,9 @@ def FindDuplicatesFilesInFolder(path):
if __name__ == '__main__': if __name__ == '__main__':
source_folder = None source_folder = None
rc, source_folder = gg.GetPathBox('DeDuplicate a Folder\'s image files', 'Enter path to folder you wish to find duplicates in') rc, source_folder = gg.GetPathBox('Duplicate Finder - Count number of duplicate files', 'Enter path to folder you wish to find duplicates in')
if rc is True and source_folder is not None: if rc is True and source_folder is not None:
FindDuplicatesFilesInFolder(source_folder) FindDuplicatesFilesInFolder(source_folder)
else: else:
gg.MsgBox('Cancelling', '*** Cancelling ***') gg.MsgBoxCancel('Cancelling', '*** Cancelling ***')
exit(0) exit(0)

View File

@ -1,5 +1,6 @@
import PySimpleGUI as sg import PySimpleGUI as sg
sg.MsgBox('Title', 'My first message... Is the length the same?')
rc, number = sg.GetTextBox('Title goes here', 'Enter a number') rc, number = sg.GetTextBox('Title goes here', 'Enter a number')
if not rc: if not rc:
sg.MsgBoxError('You have cancelled') sg.MsgBoxError('You have cancelled')
@ -7,4 +8,4 @@ if not rc:
msg = '\n'.join([f'{i}' for i in range(0,int(number))]) msg = '\n'.join([f'{i}' for i in range(0,int(number))])
sg.ScrolledTextBox(msg, Height=10) sg.ScrolledTextBox(msg, height=10)

View File

@ -15,24 +15,21 @@ def HowDoI():
:return: never returns :return: never returns
''' '''
# ------- Make a new FlexForm ------- # # ------- Make a new FlexForm ------- #
form = SG.FlexForm('How Do I ??', AutoSizeText=True, DefaultElementSize=(30, 2), Icon=DEFAULT_ICON) form = SG.FlexForm('How Do I ??', auto_size_text=True, default_element_size=(30, 2), icon=DEFAULT_ICON)
form.AddRow(SG.Text('Ask and your answer will appear here....', Size=(40, 1))) form.AddRow(SG.Text('Ask and your answer will appear here....', size=(40, 1)))
form.AddRow(SG.Output(Size=(90, 20))) form.AddRow(SG.Output(size=(90, 20)))
form.AddRow(SG.Multiline(Size=(90, 5), EnterSubmits=True), form.AddRow(SG.Multiline(size=(90, 5), enter_submits=True),
SG.ReadFormButton('SEND', ButtonColor=(SG.YELLOWS[0], SG.BLUES[0])), SG.ReadFormButton('SEND', button_color=(SG.YELLOWS[0], SG.BLUES[0])),
SG.SimpleButton('EXIT', ButtonColor=(SG.YELLOWS[0], SG.GREENS[0]))) SG.SimpleButton('EXIT', button_color=(SG.YELLOWS[0], SG.GREENS[0])))
# ---===--- Loop taking in user input and using it to query HowDoI web oracle --- # # ---===--- Loop taking in user input and using it to query HowDoI --- #
while True: while True:
(button, value) = form.Read() (button, value) = form.Read()
if button == 'SEND': if button == 'SEND':
command = value[0][:-1] QueryHowDoI(value[0][:-1]) # send string without carriage return on end
QueryHowDoI(command)
else: else:
print(button, 'pressed') break # exit button clicked
break
print('Exiting the app now')
exit(69) exit(69)
def QueryHowDoI(Query): def QueryHowDoI(Query):

View File

@ -1,12 +1,12 @@
import PySimpleGUI_local as g import PySimpleGUI as g
def SourceDestFolders(): def SourceDestFolders():
with g.FlexForm('Demo Source / Destination Folders', AutoSizeText=True) as form: with g.FlexForm('Demo Source / Destination Folders', auto_size_text=True) as form:
form_rows = [[g.Text('Enter the Source and Destination folders')], form_rows = [[g.Text('Enter the Source and Destination folders')],
[g.Text('Choose Source and Destination Folders')], [g.Text('Choose Source and Destination Folders')],
[g.Text('Source Folder', Size=(15, 1), AutoSizeText=False), g.InputText('Source'), [g.Text('Source Folder', size=(15, 1), auto_size_text=False), g.InputText('Source'),
g.FolderBrowse()], g.FolderBrowse()],
[g.Text('Destination Folder', Size=(15, 1), AutoSizeText=False), g.InputText('Dest'), [g.Text('Destination Folder', size=(15, 1), auto_size_text=False), g.InputText('Dest'),
g.FolderBrowse()], g.FolderBrowse()],
[g.Submit(), g.Cancel()]] [g.Submit(), g.Cancel()]]
@ -18,46 +18,44 @@ def SourceDestFolders():
g.MsgBoxError('Cancelled', 'User Cancelled') g.MsgBoxError('Cancelled', 'User Cancelled')
def Everything(): def Everything():
with g.FlexForm('Everything bagel', AutoSizeText=True, DefaultElementSize=(40,1)) as form: with g.FlexForm('Everything bagel', auto_size_text=True, default_element_size=(40,1)) as form:
layout = [[g.Text('All graphic widgets in one form!', Size=(30,1), Font=("Helvetica", 25), TextColor='blue')], layout = [[g.Text('All graphic widgets in one form!', size=(30,1), font=("Helvetica", 25), text_color='blue')],
[g.Text('Here is some text.... and a place to enter text')], [g.Text('Here is some text.... and a place to enter text')],
[g.InputText()], [g.InputText()],
[g.Checkbox('My first checkbox!'), g.Checkbox('My second checkbox!', Default=True)], [g.Checkbox('My first checkbox!'), g.Checkbox('My second checkbox!', default=True)],
[g.Radio('My first Radio!', "RADIO1", Default=True), g.Radio('My second Radio!', "RADIO1")], [g.Radio('My first Radio!', "RADIO1", default=True), g.Radio('My second Radio!', "RADIO1")],
[g.Multiline(DefaultText='This is the DEFAULT Text should you decide not to type anything', Scale=(2, 10))], [g.Multiline(default_text='This is the default Text should you decide not to type anything', scale=(2,10))],
[g.InputCombo(['choice 1', 'choice 2'], Size=(20, 3))], [g.InputCombo(['choice 1', 'choice 2'], size=(20,3))],
[g.Text('_' * 100, Size=(90, 1))], [g.Text('_' * 100, size=(70,1))],
[g.Text('Choose Source and Destination Folders', Size=(35,1))], [g.Text('Choose Source and Destination Folders', size=(35,1))],
[g.Text('Source Folder', Size=(15, 1), AutoSizeText=False), g.InputText('Source'), g.FolderBrowse()], [g.Text('Source Folder', size=(15,1), auto_size_text=False), g.InputText('Source'), g.FolderBrowse()],
[g.Text('Destination Folder', Size=(15, 1), AutoSizeText=False), g.InputText('Dest'), g.FolderBrowse()], [g.Text('Destination Folder', size=(15,1), auto_size_text=False), g.InputText('Dest'), g.FolderBrowse()],
[g.SimpleButton('Your very own button', ButtonColor=('white', 'green'))], [g.SimpleButton('Your very own button', button_color=('white', 'green'))],
[g.Submit(), g.Cancel()]] [g.Submit(), g.Cancel()]]
(button, (values)) = form.LayoutAndShow(layout) (button, (values)) = form.LayoutAndShow(layout)
g.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, AutoClose=True) g.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, auto_close=True)
# example of an Asynchronous form # example of an Asynchronous form
def ChatBot(): def ChatBot():
with g.FlexForm('Chat Window', AutoSizeText=True, DefaultElementSize=(30, 2)) as form: with g.FlexForm('Chat Window', auto_size_text=True, default_element_size=(30, 2)) as form:
form.AddRow(g.Text('This is where standard out is being routed', Size=[40,1])) form.AddRow(g.Text('This is where standard out is being routed', size=[40,1]))
form.AddRow(g.Output(Size=(80, 20))) form.AddRow(g.Output(size=(80, 20)))
form.AddRow(g.Multiline(Size=(70, 5), EnterSubmits=True), g.ReadFormButton('SEND', ButtonColor=(g.YELLOWS[0], g.BLUES[0])), g.SimpleButton('EXIT', ButtonColor=(g.YELLOWS[0], g.GREENS[0]))) form.AddRow(g.Multiline(size=(70, 5), enter_submits=True), g.ReadFormButton('SEND', button_color=(g.YELLOWS[0], g.BLUES[0])), g.SimpleButton('EXIT', button_color=(g.YELLOWS[0], g.GREENS[0])))
# ---===--- Loop taking in user input and using it to query HowDoI web oracle --- # # ---===--- Loop taking in user input and using it to query HowDoI web oracle --- #
while True: while True:
(button, value) = form.Read() (button, value) = form.Read()
if button == 'SEND': if button == 'SEND':
print(value) print(value, end="")
else: else:
print('Exiting the form now')
break break
print('Exiting the chatbot....')
def main(): def main():
# SourceDestFolders() SourceDestFolders()
Everything() Everything()
# ChatBot() ChatBot()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

File diff suppressed because it is too large Load Diff

420
readme.md
View File

@ -1,69 +1,69 @@
# PySimpleGUI # PySimpleGUI
This really is a simple GUI, but also powerfully customizable. This really is a simple GUI, but also powerfully customizable.
![GetTextBox](https://user-images.githubusercontent.com/13696193/42592930-1ca1370a-8519-11e8-907e-ad73e9be7749.jpg) ![GetTextBox](https://user-images.githubusercontent.com/13696193/42592930-1ca1370a-8519-11e8-907e-ad73e9be7749.jpg)
I was frustrated by having to deal with the dos prompt when I had a powerful Windows machine right in front of me. Why is it SO difficult to do even the simplest of input/output to a window in Python?? I was frustrated by having to deal with the dos prompt when I had a powerful Windows machine right in front of me. Why is it SO difficult to do even the simplest of input/output to a window in Python??
With a simple GUI, it becomes practical to "associate" .py files with the python interpreter on Windows. Double click a py file and up pops a GUI window, a more pleasant experience than opening a dos Window and typing a command line. With a simple GUI, it becomes practical to "associate" .py files with the python interpreter on Windows. Double click a py file and up pops a GUI window, a more pleasant experience than opening a dos Window and typing a command line.
Python itself doesn't have a simple GUI solution... nor did the *many* GUI packages I tried. Most tried to do TOO MUCH, making it impossible for users to get started quickly. Others were just plain broken, requiring multiple files or other packages that were missing. Python itself doesn't have a simple GUI solution... nor did the *many* GUI packages I tried. Most tried to do TOO MUCH, making it impossible for users to get started quickly. Others were just plain broken, requiring multiple files or other packages that were missing.
The PySimpleGUI solution is focused on the ***developer***. How can the desired result be achieved in as little and as simple code as possible? This was the mantra used to create PySimpleGUI. The PySimpleGUI solution is focused on the ***developer***. How can the desired result be achieved in as little and as simple code as possible? This was the mantra used to create PySimpleGUI.
You can add a GUI to your command line with a single line of code. With 3 or 4 lines of code you can add a fully customized GUI. And for you Machine Learning folks out there, a **single line** progress meter call that you can drop into any loop. You can add a GUI to your command line with a single line of code. With 3 or 4 lines of code you can add a fully customized GUI. And for you Machine Learning folks out there, a **single line** progress meter call that you can drop into any loop.
![progress meter 2](https://user-images.githubusercontent.com/13696193/42695896-a37eff5c-8684-11e8-8fbb-3d756655a44b.jpg) ![progress meter 2](https://user-images.githubusercontent.com/13696193/42695896-a37eff5c-8684-11e8-8fbb-3d756655a44b.jpg)
The customization is via the form/dialog box builder that enables users to experience all of the normal GUI widgets without having to write a lot of code. The customization is via the form/dialog box builder that enables users to experience all of the normal GUI widgets without having to write a lot of code.
Features of PySimpleGUI include:
Text Features of PySimpleGUI include:
Single Line Input Text
Buttons including these types: Single Line Input
Buttons including these types:
File Browse File Browse
Folder Browse Folder Browse
Non-closing return Non-closing return
Close form Close form
Checkboxes Checkboxes
Radio Buttons Radio Buttons
Icons Icons
Multi-line Text Input Multi-line Text Input
Scroll-able Output Scroll-able Output
Progress Bar Progress Bar
Async/Non-Blocking Windows Async/Non-Blocking Windows
Tabbed forms Tabbed forms
Persistent Windows Persistent Windows
Redirect Python Output/Errors to scrolling Window Redirect Python Output/Errors to scrolling Window
'Higher level' APIs (e.g. MessageBox, YesNobox, ...) 'Higher level' APIs (e.g. MessageBox, YesNobox, ...)
An example of many widgets used on a single form. A little further down you'll find the FIFTEEN lines of code required to create this complex form. An example of many widgets used on a single form. A little further down you'll find the FIFTEEN lines of code required to create this complex form.
![all widgets](https://user-images.githubusercontent.com/13696193/42604818-adb1dd5c-8542-11e8-94cb-575881590f21.jpg) ![all widgets](https://user-images.githubusercontent.com/13696193/42604818-adb1dd5c-8542-11e8-94cb-575881590f21.jpg)
## Getting Started with PySimpleGUI ## Getting Started with PySimpleGUI
### Installing ### Installing
pip install PySimpleGUI pip install PySimpleGUI
or or
Simply download the file - PySimpleGUI.py and import it into your code Simply download the file - PySimpleGUI.py and import it into your code
### Prerequisites ### Prerequisites
Python 3 Python 3
tkinter tkinter
Should run on all Python platforms that have tkinter running on them. Has been thoroughly tested on Windows. While not tested elsewhere, should work on Linux, Mac, Pi, etc. Should run on all Python platforms that have tkinter running on them. Has been thoroughly tested on Windows. While not tested elsewhere, should work on Linux, Mac, Pi, etc.
### Using ### Using
To use in your code, simply import.... To use in your code, simply import....
@ -106,18 +106,18 @@ This feature of the Python language is utilized ***heavily*** as a method of cus
Here is the function definition for the MsgBox function. The details aren't important. What is important is seeing that there is a long list of potential tweaks that a caller can make. However, they don't have to be specified on each and every call. Here is the function definition for the MsgBox function. The details aren't important. What is important is seeing that there is a long list of potential tweaks that a caller can make. However, they don't have to be specified on each and every call.
def MsgBox(*args, def MsgBox(*args,
ButtonColor=None, button_color=None,
ButtonType=MSG_BOX_OK, button_type=MSG_BOX_OK,
AutoClose=False, auto_close=False,
AutoCloseDuration=None, auto_close_duration=None,
Icon=DEFAULT_WINDOW_ICON, icon=DEFAULT_WINDOW_ICON,
LineWidth=MESSAGE_BOX_LINE_WIDTH, line_width=MESSAGE_BOX_LINE_WIDTH,
Font=None): font=None):
If the caller wanted to change the button color to be black on yellow, the call would look something like this: If the caller wanted to change the button color to be black on yellow, the call would look something like this:
SG.MsgBox('This box has a custom button color', SG.MsgBox('This box has a custom button color',
ButtonColor=('black', 'yellow')) button_color=('black', 'yellow'))
![custombuttoncolor](https://user-images.githubusercontent.com/13696193/42599212-84f3fe2e-852c-11e8-8a60-4aad669a1fd6.jpg) ![custombuttoncolor](https://user-images.githubusercontent.com/13696193/42599212-84f3fe2e-852c-11e8-8a60-4aad669a1fd6.jpg)
@ -194,15 +194,15 @@ We all have loops in our code. 'Isn't it joyful waiting, watching a counter scr
![progress meter 3](https://user-images.githubusercontent.com/13696193/42696332-dca3ca6e-8685-11e8-846b-6bee8362ee5f.jpg) ![progress meter 3](https://user-images.githubusercontent.com/13696193/42696332-dca3ca6e-8685-11e8-846b-6bee8362ee5f.jpg)
EasyProgressMeter(Title, EasyProgressMeter(Title,
CurrentValue, current_value,
MaxValue, max_value,
*args, *args,
Orientation=None, orientation=None,
BarColor=DEFAULT_PROGRESS_BAR_COLOR, bar_color=DEFAULT_PROGRESS_BAR_COLOR,
ButtonColor=None, button_color=None,
Size=DEFAULT_PROGRESS_BAR_SIZE, size=DEFAULT_PROGRESS_BAR_SIZE,
Scale=(None, None), scale=(None, None),
BorderWidth=DEFAULT_PROGRESS_BAR_BORDER_WIDTH): border_width=DEFAULT_PROGRESS_BAR_BORDER_WIDTH):
Here's the one-line Progress Meter in action! Here's the one-line Progress Meter in action!
@ -226,7 +226,7 @@ It's both not enjoyable nor helpful to immediately jump into tweaking each and e
## COPY THIS DESIGN PATTERN! ## COPY THIS DESIGN PATTERN!
with SG.FlexForm('SHA-1 & 256 Hash', AutoSizeText=True) as form: with SG.FlexForm('SHA-1 & 256 Hash', auto_size_text=True) as form:
form_rows = [[SG.Text('SHA-1 and SHA-256 Hashes for the file')], form_rows = [[SG.Text('SHA-1 and SHA-256 Hashes for the file')],
[SG.InputText(), SG.FileBrowse()], [SG.InputText(), SG.FileBrowse()],
[SG.Submit(), SG.Cancel()]] [SG.Submit(), SG.Cancel()]]
@ -247,7 +247,7 @@ Some elements are shortcuts, again meant to make it easy on the programmer. Rat
Going through each line of code Going through each line of code
with SG.FlexForm('SHA-1 & 256 Hash', AutoSizeText=True) as form: with SG.FlexForm('SHA-1 & 256 Hash', auto_size_text=True) as form:
This creates a new form, storing it in the variable `form`. This creates a new form, storing it in the variable `form`.
form_rows = [[SG.Text('SHA-1 and SHA-256 Hashes for the file')], form_rows = [[SG.Text('SHA-1 and SHA-256 Hashes for the file')],
@ -285,20 +285,20 @@ If you have a SINGLE value being returned, it is written this way:
## All Widgets / Elements ## All Widgets / Elements
This code utilizes as many of the elements in one form as possible. This code utilizes as many of the elements in one form as possible.
with FlexForm('Everything bagel', AutoSizeText=True, DefaultElementSize=(30,1)) as form: with FlexForm('Everything bagel', auto_size_text=True, default_element_size=(30,1)) as form:
layout = [[Text('Here they all are!', Size=(30,1), Font=("Helvetica", 25), TextColor='red')], layout = [[Text('Here they all are!', size=(30,1), font=("Helvetica", 25), text_color='red')],
[Text('Here is some text with font sizing', Font=("Helvetica", 15))], [Text('Here is some text with font sizing', font=("Helvetica", 15))],
[InputText()], [InputText()],
[Checkbox('My first checkbox!'), Checkbox('My second checkbox!', Default=True)], [Checkbox('My first checkbox!'), Checkbox('My second checkbox!', default=True)],
[Radio('My first Radio!', "RADIO1", Default=True), Radio('My second checkbox!', "RADIO1")], [Radio('My first Radio!', "RADIO1", default=True), Radio('My second checkbox!', "RADIO1")],
[Multiline(DefaultText='This is the DEFAULT text should you decide not to type anything', Scale=(2, 10))], [Multiline(DefaultText='This is the DEFAULT text should you decide not to type anything', scale=(2, 10))],
[InputCombo(['choice 1', 'choice 2'], Size=(20, 3))], [InputCombo(['choice 1', 'choice 2'], size=(20, 3))],
[Text('_' * 90, Size=(60, 1))], [Text('_' * 90, size=(60, 1))],
[Text('Choose Source and Destination Folders', Size=(35,1))], [Text('Choose Source and Destination Folders', size=(35,1))],
[Text('Source Folder', Size=(15, 1), AutoSizeText=False), InputText('Source'), FolderBrowse()], [Text('Source Folder', size=(15, 1), auto_size_text=False), InputText('Source'), FolderBrowse()],
[Text('Destination Folder', Size=(15, 1), AutoSizeText=False), InputText('Dest'), FolderBrowse()], [Text('Destination Folder', size=(15, 1), auto_size_text=False), InputText('Dest'), FolderBrowse()],
[SimpleButton('Your Button with any text you want')], [SimpleButton('Your Button with any text you want')],
[SimpleButton('Big Text', Size=(12,1), Font=("Helvetica", 20))], [SimpleButton('Big Text', size=(12,1), font=("Helvetica", 20))],
[Submit(), Cancel()]] [Submit(), Cancel()]]
(button, (values)) = form.LayoutAndShow(layout) (button, (values)) = form.LayoutAndShow(layout)
@ -306,7 +306,7 @@ This code utilizes as many of the elements in one form as possible.
MsgBox('Results', 'You clicked {}'.format(button),'The values returned from form', values , Font = ("Helvetica", 15)) MsgBox('Results', 'You clicked {}'.format(button),'The values returned from form', values , font = ("Helvetica", 15))
This is a somewhat complex form with quite a bit of custom sizing to make things line up well. This is code you only have to write once. When looking at the code, remember that what you're seeing is a list of lists. Each row contains a list of Graphical Elements that are used to create the form. This is a somewhat complex form with quite a bit of custom sizing to make things line up well. This is code you only have to write once. When looking at the code, remember that what you're seeing is a list of lists. Each row contains a list of Graphical Elements that are used to create the form.
@ -336,27 +336,27 @@ You've already seen a number of examples above that use blocking forms. Anytime
NON-BLOCKING form call: NON-BLOCKING form call:
form.Show(NonBlocking=True) form.Show(non_blocking=True)
### Beginning a Form ### Beginning a Form
The first step is to create the form object using the desired form customization. The first step is to create the form object using the desired form customization.
with FlexForm('Everything bagel', AutoSizeText=True, DefaultElementSize=(30,1)) as form: with FlexForm('Everything bagel', auto_size_text=True, default_element_size=(30,1)) as form:
Let's go through the options available when creating a form. Let's go through the options available when creating a form.
def __init__(self, title, def __init__(self, title,
DefaultElementSize=(DEFAULT_ELEMENT_SIZE[0], DEFAULT_ELEMENT_SIZE[1]), default_element_size=(DEFAULT_ELEMENT_SIZE[0], DEFAULT_ELEMENT_SIZE[1]),
AutoSizeText=DEFAULT_AUTOSIZE_TEXT, auto_size_text=DEFAULT_AUTOSIZE_TEXT,
Scale=(None, None), scale=(None, None),
Size=(None, None), size=(None, None),
Location=(None, None), location=(None, None),
ButtonColor=None,Font=None, button_color=None,Font=None,
ProgressBarColor=(None,None), progress_bar_color=(None,None),
IsTabbedForm=False, is_tabbed_form=False,
BorderDepth=None, border_depth=None,
AutoClose=False, auto_close=False,
AutoCloseDuration=DEFAULT_AUTOCLOSE_TIME, auto_close_duration=DEFAULT_AUTOCLOSE_TIME,
Icon=DEFAULT_WINDOW_ICON): icon=DEFAULT_WINDOW_ICON):
#### Sizes #### Sizes
@ -364,25 +364,25 @@ Note several variables that deal with "size". Element sizes are measured in cha
The default Element size for PySimpleGUI is `(45,1)`. The default Element size for PySimpleGUI is `(45,1)`.
Sizes can be set at the element level, or in this case, the size variables apply to all elements in the form. Setting `Size=(20,1)` in the form creation call will set all elements in the form to that size. Sizes can be set at the element level, or in this case, the size variables apply to all elements in the form. Setting `size=(20,1)` in the form creation call will set all elements in the form to that size.
In addition to `size` there is a `scale` option. Scale will take the Element's size and scale it up or down depending on the scale value. `scale=(1,1)` doesn't change the Element's size. `scale=(2,1)` will set the Element's size to be twice as wide as the size setting. In addition to `size` there is a `scale` option. `scale` will take the Element's size and scale it up or down depending on the scale value. `scale=(1,1)` doesn't change the Element's size. `scale=(2,1)` will set the Element's size to be twice as wide as the size setting.
#### FlexForm - form-level variables overview #### FlexForm - form-level variables overview
A summary of the variables that can be changed when a FlexForm is created A summary of the variables that can be changed when a FlexForm is created
DefaultElementSize - set default size for all elements in the form default_element_size - set default size for all elements in the form
AutoSizeText - true/false autosizing turned on / off auto_size_text- true/false autosizing turned on / off
Scale - set scale value for all elements scale - set scale value for all elements
ButtonColor - default button color (foreground, background) button_color- default button color (foreground, background)
Font - font name and size for all text items font - font name and size for all text items
ProgressBarColor - progress bar colors progress_bar_color - progress bar colors
IsTabbedForm - true/false indicates form is a tabbed or normal form is_tabbed_form - true/false indicates form is a tabbed or normal form
BorderDepth - style setting for buttons, input fields border_depth - style setting for buttons, input fields
AutoClose - true/false indicates if form will automatically close auto_close - true/false indicates if form will automatically close
AutoCloseDuration - how long in seconds before closing form auto_close_duration - how long in seconds before closing form
Icon - filename for icon that's displayed on the window on taskbar icon - filename for icon that's displayed on the window on taskbar
## Elements ## Elements
@ -424,11 +424,11 @@ The code is a crude representation of the GUI, laid out in text.
The most basic element is the Text element. It simply displays text. Many of the 'options' that can be set for a Text element are shared by other elements. Size, Scale are a couple that you will see in every element. The most basic element is the Text element. It simply displays text. Many of the 'options' that can be set for a Text element are shared by other elements. Size, Scale are a couple that you will see in every element.
Text(Text, Text(Text,
Scale=(None, None), scale=(None, None),
Size=(None, None), size=(None, None),
AutoSizeText=None, auto_size_text=None,
Font=None, font=None,
TextColor=None) text_color=None)
Some commonly used elements have 'shorthand' versions of the functions to make the code more compact. The functions `T` and `Txt` are the same as calling `Text`. Some commonly used elements have 'shorthand' versions of the functions to make the code more compact. The functions `T` and `Txt` are the same as calling `Text`.
@ -448,8 +448,8 @@ The values foreground and background can be the color names or the hex value for
"#RRGGBB" "#RRGGBB"
**AutoSizeText** **auto_size_text**
A `True` value for `AutoSizeText`, when placed on any Element, indicates that the width of the Element should be shrunk do the width of the text. This is particularly useful with `Buttons` as fixed-width buttons are somewhat crude looking. The default value is `False`. You will often see this setting on FlexForm definitions. A `True` value for `auto_size_text`, when placed on any Element, indicates that the width of the Element should be shrunk do the width of the text. This is particularly useful with `Buttons` as fixed-width buttons are somewhat crude looking. The default value is `False`. You will often see this setting on FlexForm definitions.
**Shorthand functions** **Shorthand functions**
The shorthand functions for `Text` are `Txt` and `T` The shorthand functions for `Text` are `Txt` and `T`
@ -457,55 +457,55 @@ The shorthand functions for `Text` are `Txt` and `T`
#### Multiline Text Element #### Multiline Text Element
layout = [[SG.Multiline('This is what a Multi-line Text Element looks like', Size=(45,5))]] layout = [[SG.Multiline('This is what a Multi-line Text Element looks like', size=(45,5))]]
![multiline text](https://user-images.githubusercontent.com/13696193/42670464-0824c754-8629-11e8-9741-6ed08f924618.jpg) ![multiline text](https://user-images.githubusercontent.com/13696193/42670464-0824c754-8629-11e8-9741-6ed08f924618.jpg)
This Element doubles as both an input and output Element. The `DefaultText` optional parameter is used to indicate what to output to the window. This Element doubles as both an input and output Element. The `DefaultText` optional parameter is used to indicate what to output to the window.
Multiline(DefaultText='', Multiline(default_text='',
EnterSubmits = False, enter_submits = False,
Scale=(None, None), scale=(None, None),
Size=(None, None), size=(None, None),
AutoSizeText=None) auto_size_text=None)
. .
DefaultText - Text to display in the text box default_text - Text to display in the text box
EnterSubmits - Bool. If True, pressing Enter key submits form enter_submits - Bool. If True, pressing Enter key submits form
Scale - Element's scale scale - Element's scale
Size - Element's size size - Element's size
AutoSizeText - Bool. Change width to match size of text auto_size_text - Bool. Change width to match size of text
#### Output Element #### Output Element
Output re-routes `Stdout` to a scrolled text box. It's used with Async forms. More on this later. Output re-routes `Stdout` to a scrolled text box. It's used with Async forms. More on this later.
form.AddRow(gg.Output(Size=(100,20))) form.AddRow(gg.Output(size=(100,20)))
![output element](https://user-images.githubusercontent.com/13696193/42704820-5446959c-869f-11e8-849e-047ea280387a.jpg) ![output element](https://user-images.githubusercontent.com/13696193/42704820-5446959c-869f-11e8-849e-047ea280387a.jpg)
Output(Scale=(None, None), Output(scale=(None, None),
Size=(None, None)) size=(None, None))
. .
Scale - How much to scale size of element scale - How much to scale size of element
Size - Size of element (width, height) in characters size - Size of element (width, height) in characters
### Input Elements ### Input Elements
These make up the majority of the form definition. Optional variables at the Element level override the Form level values (e.g. `Size` is specified in the Element). All input Elements create an entry in the list of return values. A Text Input Element creates a string in the list of items returned. These make up the majority of the form definition. Optional variables at the Element level override the Form level values (e.g. `size` is specified in the Element). All input Elements create an entry in the list of return values. A Text Input Element creates a string in the list of items returned.
#### Text Input Element #### Text Input Element
layout = [[SG.InputText('Default text')]] layout = [[SG.InputText('Default text')]]
![inputtext](https://user-images.githubusercontent.com/13696193/42693515-610a716c-867d-11e8-9a00-7e7fcf771230.jpg) ![inputtext](https://user-images.githubusercontent.com/13696193/42693515-610a716c-867d-11e8-9a00-7e7fcf771230.jpg)
def InputText(DefaultText = '', def InputText(default_text = '',
Scale=(None, None), scale=(None, None),
Size=(None, None), size=(None, None),
AutoSizeText=None) auto_size_text=None)
. .
DefaultText - Text initially shown in the input box default_text - Text initially shown in the input box
Scale - Amount size is scaled by scale - Amount size is scaled by
Size - (width, height) of element in characters size - (width, height) of element in characters
AutoSizeText - Bool. True is element should be sized to fit text auto_size_text- Bool. True is element should be sized to fit text
Shorthand functions that are equivalent to `InputText` are `Input` and `In` Shorthand functions that are equivalent to `InputText` are `Input` and `In`
@ -517,88 +517,88 @@ Also known as a drop-down list. Only required parameter is the list of choices.
![combo](https://user-images.githubusercontent.com/13696193/42694431-631c4108-8680-11e8-8e99-c1a642734464.jpg) ![combo](https://user-images.githubusercontent.com/13696193/42694431-631c4108-8680-11e8-8e99-c1a642734464.jpg)
InputCombo(Values, InputCombo(values,
Scale=(None, None), scale=(None, None),
Size=(None, None), size=(None, None),
AutoSizeText=None) auto_size_text=None)
. .
Values Choices to be displayed. List of strings values - Choices to be displayed. List of strings
Scale - Amount to scale size by scale - Amount to scale size by
Size - (width, height) of element in characters size - (width, height) of element in characters
AutoSizeText - Bool. True if size should fit the text length auto_size_text - Bool. True if size should fit the text length
#### Radio Button Element #### Radio Button Element
Creates one radio button that is assigned to a group of radio buttons. Only 1 of the buttons in the group can be selected at any one time. Creates one radio button that is assigned to a group of radio buttons. Only 1 of the buttons in the group can be selected at any one time.
layout = [[SG.Radio('My first Radio!', "RADIO1", Default=True), SG.Radio('My second radio!', "RADIO1")]] layout = [[SG.Radio('My first Radio!', "RADIO1", default=True), SG.Radio('My second radio!', "RADIO1")]]
![radio element](https://user-images.githubusercontent.com/13696193/42705705-327b4b6c-86a2-11e8-81a7-740e57646ba8.jpg) ![radio element](https://user-images.githubusercontent.com/13696193/42705705-327b4b6c-86a2-11e8-81a7-740e57646ba8.jpg)
Radio(Text, Radio(text,
GroupID, group_id,
Default=False, default=False,
Scale=(None, None), scale=(None, None),
Size=(None, None), size=(None, None),
AutoSizeText=None, auto_size_text=None,
Font=None) font=None)
. .
Text - Text to display next to button text - Text to display next to button
GroupID - Groups together multiple Radio Buttons. Can be any value group_id - Groups together multiple Radio Buttons. Can be any value
Default - Bool. Initial state default - Bool. Initial state
Scale - Amount to scale size of element scale - Amount to scale size of element
Size - (width, height) size of element in characters size- (width, height) size of element in characters
AutoSizeText - Bool. True if should size width to fit text auto_size_text - Bool. True if should size width to fit text
Font - Font type and size for text display font - Font type and size for text display
#### Checkbox Element #### Checkbox Element
Checkbox elements are like Radio Button elements. They return a bool indicating whether or not they are checked. Checkbox elements are like Radio Button elements. They return a bool indicating whether or not they are checked.
layout = [[SG.Checkbox('My first Checkbox!', Default=True), SG.Checkbox('My second Checkbox!')]] layout = [[SG.Checkbox('My first Checkbox!', default=True), SG.Checkbox('My second Checkbox!')]]
![checkbox element](https://user-images.githubusercontent.com/13696193/42717015-655d73d2-86cc-11e8-9c69-3c810f48e578.jpg) ![checkbox element](https://user-images.githubusercontent.com/13696193/42717015-655d73d2-86cc-11e8-9c69-3c810f48e578.jpg)
Checkbox(Text, Checkbox(text,
Default=False, default=False,
Scale=(None, None), scale=(None, None),
Size=(None, None), size=(None, None),
AutoSizeText=None, auto_size_text=None,
Font=None): font=None):
. .
Text - Text to display next to checkbox text - Text to display next to checkbox
Default - Bool. Initial state default- Bool. Initial state
Scale - Amount to scale size of element scale - Amount to scale size of element
Size - (width, height) size of element in characters size - (width, height) size of element in characters
AutoSizeText - Bool. True if should size width to fit text auto_size_text- Bool. True if should size width to fit text
Font - Font type and size for text display font- Font type and size for text display
#### Spin Element #### Spin Element
An up/down spinner control. The valid values are passed in as a list. An up/down spinner control. The valid values are passed in as a list.
layout = [[SG.Spin([i for i in range(1,11)], InitialValue=1), SG.Text('Volume level')]] layout = [[SG.Spin([i for i in range(1,11)], initial_value=1), SG.Text('Volume level')]]
![spin element](https://user-images.githubusercontent.com/13696193/42717231-8ddb51d4-86cd-11e8-827a-75f2237477fa.jpg) ![spin element](https://user-images.githubusercontent.com/13696193/42717231-8ddb51d4-86cd-11e8-827a-75f2237477fa.jpg)
Spin(Values, Spin(values,
InitialValue=None, intiial_value=None,
Scale=(None, None), scale=(None, None),
Size=(None, None), size=(None, None),
AutoSizeText=None, auto_size_text=None,
Font=None) font=None)
. .
Values - List of valid values values - List of valid values
InitialValue - String with initial value initial_value - String with initial value
Scale - Amount to scale size of element scale - Amount to scale size of element
Size - (width, height) size of element in characters size - (width, height) size of element in characters
AutoSizeText - Bool. True if should size width to fit text auto_size_text - Bool. True if should size width to fit text
Font - Font type and size for text display font - Font type and size for text display
#### Button Element #### Button Element
Buttons are the most important element of all! They cause the majority of the action to happen. After all, it's a button press that will get you out of a form, whether it but Submit or Cancel, one way or another a button is involved in all forms. The only exception is to this is when the user closes the window using the "X" in the upper corner which means no button was involved. Buttons are the most important element of all! They cause the majority of the action to happen. After all, it's a button press that will get you out of a form, whether it but Submit or Cancel, one way or another a button is involved in all forms. The only exception is to this is when the user closes the window using the "X" in the upper corner which means no button was involved.
@ -620,12 +620,12 @@ Read Form - This is an async form button that will read a snapshot of all of the
While it's possible to build forms using the Button Element directly, you should never need to do that. There are pre-made buttons and shortcuts that will make life much easier. The most basic Button element call to use is `SimpleButton` While it's possible to build forms using the Button Element directly, you should never need to do that. There are pre-made buttons and shortcuts that will make life much easier. The most basic Button element call to use is `SimpleButton`
SimpleButton(Text, SimpleButton(text,
Scale=(None, None), scale=(None, None),
Size=(None, None), size=(None, None),
AutoSizeText=None, auto_size_text=None,
ButtonColor=None, button_color=None,
Font=None) font=None)
Pre-made buttons include: Pre-made buttons include:
@ -667,16 +667,16 @@ layout = [[SG.SimpleButton('My Button')]]
![singlebutton](https://user-images.githubusercontent.com/13696193/42718281-9453deca-86d5-11e8-83c7-4b6d33720858.jpg) ![singlebutton](https://user-images.githubusercontent.com/13696193/42718281-9453deca-86d5-11e8-83c7-4b6d33720858.jpg)
All buttons can have their text changed by changing the `ButtonText` variable. All buttons can have their text changed by changing the `button_text` variable.
**File Types** **File Types**
The `FileBrowse` button has an additional setting named `FileTypes`. This variable is used to filter the files shown in the file dialog box. The default value for this setting is The `FileBrowse` button has an additional setting named `file_types`. This variable is used to filter the files shown in the file dialog box. The default value for this setting is
FileTypes=(("ALL Files", "*.*"),) FileTypes=(("ALL Files", "*.*"),)
This code produces a form where the Browse button only shows files of type .TXT This code produces a form where the Browse button only shows files of type .TXT
layout = [[SG.In() ,SG.FileBrowse(FileTypes=(("Text Files", "*.txt"),))]] layout = [[SG.In() ,SG.FileBrowse(file_types=(("Text Files", "*.txt"),))]]
***The ENTER key*** ***The ENTER key***
The ENTER key is an important part of data entry for forms. There's a long tradition of the enter key being used to quickly submit forms. PySimpleGUI implements this tying the ENTER key to the first button that closes or reads a form. If there are more than 1 button on a form, the FIRST button that is of type Close Form or Read Form is used. First is determined by scanning the form, top to bottom and left to right. Keep this in mind when designing forms. The ENTER key is an important part of data entry for forms. There's a long tradition of the enter key being used to quickly submit forms. PySimpleGUI implements this tying the ENTER key to the first button that closes or reads a form. If there are more than 1 button on a form, the FIRST button that is of type Close Form or Read Form is used. First is determined by scanning the form, top to bottom and left to right. Keep this in mind when designing forms.
@ -693,23 +693,23 @@ If you want a bit more customization of your meter, then you can go up 1 level a
You setup the progress meter by calling You setup the progress meter by calling
my_meter = ProgressMeter(Title, my_meter = ProgressMeter(title,
MaxValue, max_value,
*args, *args,
Orientation=None, orientantion=None,
BarColor=DEFAULT_PROGRESS_BAR_COLOR, bar_color=DEFAULT_PROGRESS_BAR_COLOR,
ButtonColor=None, button_color=None,
Size=DEFAULT_PROGRESS_BAR_SIZE, size=DEFAULT_PROGRESS_BAR_SIZE,
Scale=(None, None), scale=(None, None),
BorderWidth=DEFAULT_PROGRESS_BAR_BORDER_WIDTH) border_width=DEFAULT_PROGRESS_BAR_BORDER_WIDTH)
Then to update the bar within your loop Then to update the bar within your loop
return_code = ProgressMeterUpdate(my_meter, return_code = ProgressMeterUpdate(my_meter,
Value, value,
*args): *args):
Putting it all together you get this design pattern Putting it all together you get this design pattern
my_meter = SG.ProgressMeter('Meter Title', 100000, Orientation='Vert') my_meter = SG.ProgressMeter('Meter Title', 100000, orentation='Vert')
for i in range(0, 100000): for i in range(0, 100000):
SG.ProgressMeterUpdate(my_meter, i+1, 'Some variable', 'Another variable') SG.ProgressMeterUpdate(my_meter, i+1, 'Some variable', 'Another variable')
@ -720,17 +720,17 @@ The final way of using a Progress Meter with PySimpleGUI is to build a custom fo
#### Output #### Output
The Output Element is a re-direction of Stdout. Anything "printed" will be displayed in this element. The Output Element is a re-direction of Stdout. Anything "printed" will be displayed in this element.
Output(Scale=(None, None), Output(scale=(None, None),
Size=(None, None)) size=(None, None))
Here's a complete solution for a chat-window using an Async form with an Output Element Here's a complete solution for a chat-window using an Async form with an Output Element
import PySimpleGUI as g import PySimpleGUI as g
with g.FlexForm('Chat Window', AutoSizeText=True, DefaultElementSize=(30, 2)) as form: with g.FlexForm('Chat Window', auto_size_text=True, default_element_size=(30, 2)) as form:
form.AddRow(g.Text('This is where standard out is being routed', Size=[40,1])) form.AddRow(g.Text('This is where standard out is being routed', size=[40,1]))
form.AddRow(g.Output(Size=(80, 20))) form.AddRow(g.Output(size=(80, 20)))
form.AddRow(g.Multiline(Size=(70, 5), EnterSubmits=True), g.ReadFormButton('SEND', ButtonColor=(g.YELLOWS[0], g.BLUES[0])), g.SimpleButton('EXIT', ButtonColor=(g.YELLOWS[0], g.GREENS[0]))) form.AddRow(g.Multiline(size=(70, 5), enter_submits=True), g.ReadFormButton('SEND', button_color=(g.YELLOWS[0], g.BLUES[0])), g.SimpleButton('EXIT', button_color=(g.YELLOWS[0], g.GREENS[0])))
# ---===--- Loop taking in user input and printing it --- # # ---===--- Loop taking in user input and printing it --- #
while True: while True:
@ -773,9 +773,11 @@ While not an "issue" this is a *stern warning*
A MikeTheWatchGuy production... entirely responsible for this code.... unless it causes you trouble in which case I'm not at all responsible. A MikeTheWatchGuy production... entirely responsible for this code.... unless it causes you trouble in which case I'm not at all responsible.
## Versioning ## Versioning
|Version | Description |
1.0.9 - July 10, 2018 - Initial Release |--|--|
1.0.21 - July 13, 2018 - Readme updates | 1.0.9 | July 10, 2018 - Initial Release |
| 1.0.21 | July 13, 2018 - Readme updates |
| 2.0 | July 16, 2018 - ALL optional parameters renamed from CamelCase to all_lower_case
## Code Condition ## Code Condition