Merge pull request #2009 from PySimpleGUI/Dev-latest

Dev latest
This commit is contained in:
PySimpleGUI 2019-09-20 17:31:22 -04:00 committed by GitHub
commit 2cf84deda4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 128 additions and 757 deletions

View File

@ -7,13 +7,13 @@ EDGE_OFFSET = 3
GRAPH_SIZE = (500,500)
DATA_SIZE = (500,500)
graph = sg.Graph(GRAPH_SIZE, (0, 0), DATA_SIZE)
graph = sg.Graph(GRAPH_SIZE, (0,0), DATA_SIZE)
layout = [[sg.Text('Bar graphs using PySimpleGUI')],
[graph],
[sg.Button('OK')]]
window = sg.Window('Window Title').Layout(layout)
window = sg.Window('Window Title', layout)
while True:
event, values = window.Read()
@ -25,4 +25,5 @@ while True:
graph_value = random.randint(0, 400)
graph.DrawRectangle(top_left=(i * BAR_SPACING + EDGE_OFFSET, graph_value),
bottom_right=(i * BAR_SPACING + EDGE_OFFSET + BAR_WIDTH, 0), fill_color='blue')
graph.DrawText(text=graph_value, location=(i*BAR_SPACING+EDGE_OFFSET+25, graph_value+10))
graph.DrawText(text=graph_value, location=(i*BAR_SPACING+EDGE_OFFSET+25, graph_value+10))
window.Close()

View File

@ -19,7 +19,7 @@ def main():
sg.PopupCancel('Cancelled - No valid folder entered')
return
try:
namesonly = [f for f in os.listdir(folder) if f.endswith('.png') or f.endswith('.ico')]
namesonly = [f for f in os.listdir(folder) if f.endswith('.png') or f.endswith('.ico') or f.endswith('.gif')]
except:
sg.PopupCancel('Cancelled - No valid folder entered')
return

View File

@ -17,10 +17,10 @@ layout = [[sg.T('User:', pad=((3, 0), 0)), sg.OptionMenu(values=('User 1', 'User
[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=('gray50', 'black')),
sg.ReadButton('Reset', button_color=('white', '#9B0023')),
sg.ReadButton('Submit', button_color=('gray60', 'springgreen4')),
[sg.Button('Start', button_color=('white', 'black')),
sg.Button('Stop', button_color=('gray50', 'black')),
sg.Button('Reset', button_color=('white', '#9B0023')),
sg.Button('Submit', button_color=('gray60', 'springgreen4')),
sg.Button('Exit', button_color=('white', '#00406B'))]]
window = sg.Window("Borderless Window",

View File

@ -11,14 +11,14 @@ if not sys.platform.startswith('win'):
import winsound
sg.ChangeLookAndFeel('Dark')
sg.SetOptions(element_padding=(0,0))
# sg.ChangeLookAndFeel('Dark')
# sg.SetOptions(element_padding=(0,0))
layout = [
[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.Button('Start', button_color=('white', 'black'), key='start'),
sg.Button('Stop', button_color=('white', 'black'), key='stop'),
sg.Button('Reset', button_color=('white', 'firebrick3'), key='reset'),
sg.Button('Submit', button_color=('white', 'springgreen4'), key='submit')]
]
window = sg.Window("Button Click", default_element_size=(12,1), text_justification='r', auto_size_text=False, auto_size_buttons=False, default_button_element_size=(12,1), use_default_focus=False).Layout(layout).Finalize()
@ -27,7 +27,7 @@ window.FindElement('submit').Update(disabled=True)
recording = have_data = False
while True:
event, values = window.Read()
event, values = window.Read(timeout=100)
if event is None:
sys.exit(69)
winsound.PlaySound("ButtonClick.wav", 1)
winsound.PlaySound("ButtonClick.wav", 1) if event != sg.TIMEOUT_KEY else None

View File

@ -16,10 +16,10 @@ 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'), 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.Button('Start', button_color=('white', 'black'), key='_Start_'),
sg.Button('Stop', button_color=('white', 'black'), key='_Stop_'),
sg.Button('Reset', button_color=('white', 'firebrick3'), key='_Reset_'),
sg.Button('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).Finalize()

View File

@ -7,7 +7,7 @@ else:
layout = [
[sg.Canvas(size=(150, 150), background_color='red', key='canvas')],
[sg.T('Change circle color to:'), sg.ReadButton('Red'), sg.ReadButton('Blue')]
[sg.T('Change circle color to:'), sg.Button('Red'), sg.Button('Blue')]
]
window = sg.Window('Canvas test').Layout(layout).Finalize()

View File

@ -23,7 +23,7 @@ def ChatBotWithHistory():
[sg.Output(size=(127, 30), font=('Helvetica 10'))],
[sg.T('Command History'), sg.T('', size=(20,3), key='history')],
[sg.Multiline(size=(85, 5), enter_submits=True, key='query', do_not_clear=False),
sg.ReadButton('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True),
sg.Button('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True),
sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))]]
window = sg.Window('Chat window with history', default_element_size=(30, 2), font=('Helvetica',' 13'), default_button_element_size=(8,2), return_keyboard_events=True).Layout(layout)

View File

@ -103,8 +103,8 @@ class GameOfLife:
[sg.Text('Game of Life ', font='ANY 15'), sg.Text('', key='_OUTPUT_', size=(30,1), font='ANY 15')],
[self.graph],
[sg.Button('Go!', key='_DONE_'),
sg.Text(' Delay (ms)') , sg.Slider([0,400], orientation='h', key='_SLIDER_', enable_events=True, size=(15,15)), sg.T('', size=(3,1), key='_S1_OUT_'),
sg.Text(' Num Generations'), sg.Slider([0, 3000],default_value=400, orientation='h',size=(15,15),enable_events=True, key='_SLIDER2_'), sg.T('', size=(3,1), key='_S2_OUT_')]
sg.Text(' Delay (ms)') , sg.Slider([0,800], orientation='h', key='_SLIDER_', enable_events=True, size=(15,15)), sg.T('', size=(3,1), key='_S1_OUT_'),
sg.Text(' Num Generations'), sg.Slider([0, 20000],default_value=4000, orientation='h',size=(15,15),enable_events=True, key='_SLIDER2_'), sg.T('', size=(3,1), key='_S2_OUT_')]
]
self.window = sg.Window('Window Title', ).Layout(layout).Finalize()

View File

@ -1,6 +1,6 @@
import sys
if sys.version_info[0] >= 3:
import PySimpleGUIQt as sg
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg

View File

@ -8,7 +8,7 @@ import PySimpleGUI as sg
layout = [[ sg.Text('Window 1'),],
[sg.Input(do_not_clear=True)],
[sg.Text('', key='_OUTPUT_')],
[sg.Text('', size=(20,1), key='_OUTPUT_')],
[sg.Button('Launch 2')]]
win1 = sg.Window('Window 1').Layout(layout)

View File

@ -8,7 +8,7 @@ import PySimpleGUI as sg
layout = [[ sg.Text('Window 1'),],
[sg.Input(do_not_clear=True)],
[sg.Text('', key='_OUTPUT_')],
[sg.Text('', size=(20,1), key='_OUTPUT_')],
[sg.Button('Launch 2'), sg.Button('Exit')]]
win1 = sg.Window('Window 1').Layout(layout)

View File

@ -2,7 +2,7 @@ import PySimpleGUI as sg
layout = [[sg.Text('Window 1'), ],
[sg.Input(do_not_clear=True)],
[sg.Text('', key='_OUTPUT_')],
[sg.Text('',size=(20,1), key='_OUTPUT_')],
[sg.Button('Next >'), sg.Button('Exit')]]
win1 = sg.Window('Window 1').Layout(layout)

View File

@ -1,13 +1,12 @@
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
layout = [
[sg.Text('Your typed chars appear here:'), sg.Text('', key='_OUTPUT_')],
[sg.Input(do_not_clear=True, key='_IN_')],
[sg.Text('Your typed chars appear here:'), sg.Text('', size=(20,1), key='-OUTPUT-')],
[sg.Input(do_not_clear=True, key='-IN-')],
[sg.Button('Show'), sg.Button('Exit')]
]
@ -20,6 +19,6 @@ while True: # Event Loop
break
if event == 'Show':
# change the "output" element to be the value of "input" element
window.FindElement('_OUTPUT_').Update(values['_IN_'])
window.FindElement('-OUTPUT-').Update(values['-IN-'])
window.Close()

View File

@ -2,59 +2,53 @@
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
1. A "One Shot" window
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
3. A persistent window that need to perform Update of an element before the window.read
"""
# ---------------------------------#
# DESIGN PATTERN 1 - Simple Window #
# ---------------------------------#
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import PySimpleGUI as sg
layout = [[ sg.Text('My layout') ]]
layout = [[ sg.Text('My Oneshot') ],
[ sg.Button('OK') ]]
window = sg.Window('My window').Layout(layout)
event, values = window.Read()
window = sg.Window('My Oneshot', layout)
event, values = window.read()
window.close()
# -------------------------------------#
# DESIGN PATTERN 2 - Persistent Window #
# -------------------------------------#
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import PySimpleGUI as sg
layout = [[ sg.Text('My layout') ]]
layout = [[ sg.Text('My layout') ],
[ sg.Button('OK'), sg.Button('Cancel') ]]
window = sg.Window('My new window').Layout(layout)
window = sg.Window('Design Pattern 2', layout)
while True: # Event Loop
event, values = window.Read()
if event is None:
event, values = window.read()
if event in (None, 'Cancel'):
break
window.close()
# ------------------------------------------------------------------#
# DESIGN PATTERN 3 - Persistent Window with "early update" required #
# ------------------------------------------------------------------#
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import PySimpleGUI as sg
layout = [[ sg.Text('My layout') ]]
layout = [[ sg.Text('My layout', key='-TEXT-KEY-') ],
[ sg.Button('OK'), sg.Button('Cancel') ]]
window = sg.Window('My new window').Layout(layout).Finalize()
window = sg.Window('Design Pattern 3', layout, finalize=True)
# if you have operations on elements that must take place before the event loop, do them here
window['-TEXT-KEY-'].Update('NEW Text') # Change the text field. Finalize allows us to do this
while True: # Event Loop
event, values = window.Read()
if event is None:
break
event, values = window.read()
if event in (None, 'Cancel'):
break
window.close()

View File

@ -35,10 +35,10 @@ def Launcher():
sg.SetOptions(element_padding=(0,0), button_element_size=(12,1), auto_size_buttons=False)
layout = [[sg.Combo(values=namesonly, size=(35,30), key='demofile'),
sg.ReadButton('Run', button_color=('white', '#00168B')),
sg.ReadButton('Program 1'),
sg.ReadButton('Program 2'),
sg.ReadButton('Program 3', button_color=('white', '#35008B')),
sg.Button('Run', button_color=('white', '#00168B')),
sg.Button('Program 1'),
sg.Button('Program 2'),
sg.Button('Program 3', button_color=('white', '#35008B')),
sg.Button('EXIT', button_color=('white','firebrick3'))],
[sg.T('', text_color='white', size=(50,1), key='output')]]

View File

@ -17,10 +17,10 @@ layout = [
[sg.Spin((1,2,3,4),1,disabled=True, key='spin'), sg.OptionMenu((1,2,3,4),disabled=True, key='option'), sg.Combo(values=(1,2,3,4),disabled=True,key='combo')],
[sg.Multiline('Multiline', size=(20,3),disabled=True, key='multi')],
[sg.Slider((1,10), size=(20,20), orientation='h', disabled=True, key='slider')],
[sg.ReadButton('Enable', button_color=('white', 'black')),
sg.ReadButton('Disable', button_color=('white', 'black')),
sg.ReadButton('Reset', button_color=('white', '#9B0023'), key='reset'),
sg.ReadButton('Values', button_color=('white', 'springgreen4')),
[sg.Button('Enable', button_color=('white', 'black')),
sg.Button('Disable', button_color=('white', 'black')),
sg.Button('Reset', button_color=('white', '#9B0023'), key='reset'),
sg.Button('Values', button_color=('white', 'springgreen4')),
sg.Button('Exit', disabled=True, button_color=('white', '#00406B'), key='exit')]]
window = sg.Window("Disable Elements Demo", default_element_size=(12, 1), text_justification='r', auto_size_text=False,

View File

@ -7,7 +7,7 @@ else:
import PySimpleGUI27 as sg
def Everything():
sg.ChangeLookAndFeel('BlueMono')
sg.ChangeLookAndFeel('TanBlue')
column1 = [
[sg.Text('Column 1', background_color=sg.DEFAULT_BACKGROUND_COLOR, justification='center', size=(10, 1))],
@ -37,8 +37,8 @@ def Everything():
[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', key='folder', do_not_clear=True), sg.FolderBrowse()],
[sg.ReadButton('Exit'),
sg.Text(' ' * 40), sg.ReadButton('SaveSettings'), sg.ReadButton('LoadSettings')]
[sg.Button('Exit'),
sg.Text(' ' * 40), sg.Button('SaveSettings'), sg.Button('LoadSettings')]
]
window = sg.Window('Form Fill Demonstration', default_element_size=(40, 1), grab_anywhere=False)

View File

@ -6,7 +6,7 @@ else:
import PySimpleGUI27 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')]]
[sg.T('Change circle color to:'), sg.Button('Red'), sg.Button('Blue'), sg.Button('Move')]]
window = sg.Window('Graph test').Layout(layout).Finalize()

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
import PySimpleGUIQt as sg
else:
import PySimpleGUI27 as sg
import subprocess
@ -26,12 +26,12 @@ def HowDoI():
layout = [
[sg.Text('Ask and your answer will appear here....', size=(40, 1))],
[sg.Output(size=(127, 30), font=('Helvetica 10'))],
[sg.Output(size=(120, 30), font=('Helvetica 10'))],
[ sg.Spin(values=(1, 2, 3, 4), initial_value=1, size=(2, 1), key='Num Answers', font='Helvetica 15'),
sg.Text('Num Answers',font='Helvetica 15'), sg.Checkbox('Display Full Text', key='full text', font='Helvetica 15'),
sg.T('Command History', font='Helvetica 15'), sg.T('', size=(40,3), text_color=sg.BLUES[0], key='history')],
[sg.Multiline(size=(85, 5), enter_submits=True, key='query', do_not_clear=False),
sg.ReadButton('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True),
sg.Button('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True),
sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))]
]

View File

@ -77,7 +77,7 @@ col = [[filename_display_elem],
[image_elem]]
col_files = [[sg.Listbox(values = fnames, change_submits=True, size=(60, 30), key='listbox')],
[sg.ReadButton('Next', size=(8,2)), sg.ReadButton('Prev',
[sg.Button('Next', size=(8,2)), sg.Button('Prev',
size=(8,2)), file_num_display_elem]]
layout = [[sg.Column(col_files), sg.Column(col)]]

View File

@ -1,656 +0,0 @@
#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
from tkinter import Tk
else:
import PySimpleGUI27 as sg
from Tkinter import Tk
desc_text = """
Text( text
size=(None, None)
auto_size_text=None
click_submits=None
relief=None
font=None
text_color=None
background_color=None
justification=None
pad=None
key=None
tooltip=None)
Shortcuts: Txt, T
"""
desc_inputtext = """
InputText( default_text =''
size=(None, None)
disabled=False
auto_size_text=None
password_char=''
justification=None
background_color=None
text_color=None
font=None
tooltip=None
do_not_clear=False
key=None
focus=False
pad=None)
Shortcuts: In, Input
"""
desc_inputcombo = """
InputCombo( values
default_value=None
size=(None, None)
auto_size_text=None
background_color=None
text_color=None
change_submits=False
disabled=False
key=None
pad=None
tooltip=None)
Shortcuts: Combo, DropDown, Drop
"""
desc_inputoptionmenu = """
InputOptionMenu(values
default_value=None
size=(None, None)
disabled=False
auto_size_text=None
background_color=None
text_color=None
key=None
pad=None
tooltip=None)
Shortcuts: OptionMenu
"""
desc_listbox = """
Listbox(values
default_values=None
select_mode=None
change_submits=False
bind_return_key=False
size=(None, None)
auto_size_text=None
font=None
background_color=None
text_color=None
key=None
pad=None
tooltip=None)
"""
desc_checkbox = """
CheckBox( text
default=False
size=(None, None)
auto_size_text=None
font=None
background_color=None
text_color=None
change_submits=False
disabled=False
key=None
pad=None
tooltip=None)
Shortcuts: CB, CBox, Check
"""
desc_radio = """
Radio( text
group_id
default=False
disabled=False
size=(None, None)
auto_size_text=None
background_color=None
text_color=None
font=None
key=None
pad=None
tooltip=None)
"""
desc_spin = """
Spin( values
initial_value=None
disabled=False
change_submits=False
size=(None, None)
auto_size_text=None
font=None
background_color=None
text_color=None
key=None
pad=None
tooltip=None)
"""
desc_multiline = """
MultiLine( default_text=''
enter_submits = False
disabled=False
autoscroll=False
size=(None,None)
auto_size_text=None
background_color=None
text_color=None
do_not_clear=False
key=None
focus=False
pad=None
tooltip=None)
"""
desc_output = """
Output( size=(None, None)
background_color=None
text_color=None
pad=None
font=None
tooltip=None
key=None)
"""
desc_button = """
Button( button_text=''
button_type=BUTTON_TYPE_CLOSES_WIN
target=(None, None)
tooltip=None
file_types=(("ALL Files", "*.*"),)
initial_folder=None
disabled=False
image_filename=None
image_size=(None, None)
image_subsample=None
border_width=None
size=(None, None)
auto_size_button=None
button_color=None
default_value = None
font=None
bind_return_key=False
focus=False
pad=None
key=None)
"""
desc_progressbar = """
ProgressBar(max_value
orientation=None
size=(None, None)
auto_size_text=None
bar_color=(None, None)
style=None
border_width=None
relief=None
key=None
pad=None)
"""
desc_image = """
Image( filename=None
data=None
size=(None, None)
pad=None
key=None
tooltip=None)
"""
desc_canvas = """
Canvas( canvas=None
background_color=None
size=(None, None)
pad=None
key=None
tooltip=None)
"""
desc_graph = """
Graph( canvas_size
graph_bottom_left
graph_top_right
background_color=None
pad=None
key=None
tooltip=None)
"""
desc_frame = """
Frame( title
layout
title_color=None
background_color=None
title_location=None
relief=DEFAULT_FRAME_RELIEF
size=(None, None)
font=None
pad=None
border_width=None
key=None
tooltip=None)
"""
desc_tab = """
Tab(title
layout
title_color=None
background_color=None
font=None
pad=None
disabled=False
border_width=None
key=None
tooltip=None)
"""
desc_tabgroup = """
TabGroup( layout
tab_location=None
title_color=None
selected_title_color=None
background_color=None
font=None
change_submits=False
pad=None
border_width=None
theme=None
key=None
tooltip=None)
"""
desc_slider = """
Slider( range=(None,None)
default_value=None
resolution=None
orientation=None
border_width=None
relief=None
change_submits=False
disabled=False
size=(None, None)
font=None
background_color=None
text_color=None
key=None
pad=None
tooltip=None)
"""
desc_spin = """
Spin( values
initial_value=None
disabled=False
change_submits=False
size=(None, None)
auto_size_text=None
font=None
background_color=None
text_color=None
key=None
pad=None
tooltip=None)
"""
desc_tree = """
Tree( data=None,
headings=None,
visible_column_map=None,
col_widths=None,
col0_width=10,
def_col_width=10,
auto_size_columns=True,
max_col_width=20,
select_mode=None,
font=None,
justification='right',
text_color=None,
background_color=None,
num_rows=None,
pad=None,
key=None,
tooltip=None):
"""
desc_column = """
Column( layout
background_color = None
size=(None, None)
pad=None
scrollable=False
key=None)
"""
desc_table = """
Table( values
headings=None
visible_column_map=None
col_widths=None
def_col_width=10
auto_size_columns=True
max_col_width=20
select_mode=None
display_row_numbers=False
scrollable=None
font=None
justification='right'
text_color=None
background_color=None
size=(None, None)
pad=None
key=None
tooltip=None)
"""
desc_window = """
Window( title
default_element_size=DEFAULT_ELEMENT_SIZE
default_button_element_size = (None, None)
auto_size_text=None
auto_size_buttons=None
location=(None, None)
button_color=None
font=None
progress_bar_color=(None, None)
background_color=None
border_depth=None
auto_close=False
auto_close_duration=DEFAULT_AUTOCLOSE_TIME
icon=DEFAULT_WINDOW_ICON
force_toplevel = False
return_keyboard_events=False
use_default_focus=True
text_justification=None
no_titlebar=False
grab_anywhere=False
keep_on_top=False
resizable=False)
"""
desc_window_methods = """
Layout(rows)
Call to set the window layout. Must be called prior to Read. Most likely "chained" in line with the Window creation.
Finalize()
Call to force a window to go through the final stages of initialization. This will cause the tkinter resources to be allocated so that they can then be modified.
Read()
Read the Window's input values and button clicks in a blocking-fashion
Returns event, values
ReadNonBlocking()
Read the Window's input values and button clicks but without blocking. It will immediately return.
Refresh()
Cause changes to the window to be displayed on the screen. Normally not needed unless the changes are immediately required or if it's going to be a while before another call to Read.
SetIcon(icon)
Sets the window's icon that will be shown on the titlebar.
Fill(values_dict)
Populates the windows fields with the values shown in the dictionary.
FindElement(key)
Rerturns the Element that has a matching key. If the key is not found, an Error Element is returned so that the program will not crash should the user try to perform an "update". A Popup message will be shown
SaveToDisk(filename)
Saves the window's values to disk
LoadFromDisk(filename)
Fills in a window's fields based on previously saved file
GetScreenDimensions()
Returns the size (w,h) of the screen in pixels
Move(x, y)
Move window to (x,y) position on the screen
Minimize()
Sends the window to the taskbar
CloseNonBlocking()
Closes a non-blocking window
Disable()
Stops a window from responding until Enable is called
Enable()
Re-enables a previously disabled window
Hide()
Completely hides a window, including removing from the taskbar
UnHide()
Restores a window hidden using Hide
Disappear()
Makes a window disappear while leaving the icon on the taskbar
Reappear()
Makes a window reappear that was previously made to disappear using Disappear()
SetAlpha(alpha)
Sets the window's transparency. 0 is completely transparent. 1 is fully visible, normal
"""
desc_menu= """
Menu(menu_definition
background_color=None
size=(None, None)
tearoff=True
pad=None
key=None)
"""
desc_button_types = """
There are multiple button types / names to choose from
CloseButton = CButton = SimpleButton
Button = ReadFormButton = ReadButton = RButton
RealtimeButton
DummyButton
FolderBrowse
FileBrowse
FilesBrowse
FileSaveAs = SaveAs
CalendarButton
ColorChooserButton
Shortcuts - Normal buttons with predefined text
Save, Open, OK, Ok, Cancel, Quit, Exit, Yes, No, Help
"""
desc_popup= """
Popup(button_color=None
background_color=None
text_color=None
button_type=POPUP_BUTTONS_OK
auto_close=False
auto_close_duration=None
non_blocking=False
icon=DEFAULT_WINDOW_ICON
line_width=None
font=None
no_titlebar=False
grab_anywhere=False
keep_on_top=False
location=(None,None))
"""
desc_popups = """
PopupScrolled
PopupGetFolder
PopupGetFile
PopupGetText
POopup
PopupNoButtons
PopupNonBlocking = PopupNoWait
PopupQuick
PopupNoTitleBar = PopupNoFrame = PopupNoBorder = PopupAnnoying
PopupAutoClose = PopupTimed
PopupError
PopupCancel
PopupOK
PopupOKCancel
PopupYesNo
"""
desc_one_line_progress_meter = """
OneLineProgressMeter(title
current_value
max_value
key
*args
orientation=None
bar_color=(None,None)
button_color=None
size=DEFAULT_PROGRESS_BAR_SIZE
border_width=None
grab_anywhere=False):
"""
element_list = ('Window',
'Text',
'InputText',
'CheckBox',
'RadioButton',
'Listbox',
'InputCombo',
'Slider',
'Spinner',
'Multiline',
'Output',
'ProgressBar',
'OptionMenu',
'Menu',
'Frame',
'Column',
'Graph',
'Image',
'Table',
'Tab',
'TabGroup',
'Button Types')
descriptions = {'Window': desc_window, 'Text': desc_text, 'InputText': desc_inputtext, 'Checkbox': desc_checkbox,
'Radio': desc_radio, 'Listbox': desc_listbox, 'Slider': desc_slider, 'Spinner':desc_spin, 'Multiline': desc_multiline,
'Output': desc_output, 'ProgressBar': desc_progressbar, 'OptionMenu': desc_inputoptionmenu,
'Combo': desc_inputcombo, 'Menu': desc_menu, 'Frame': desc_frame, 'Column': desc_column,
'Graph': desc_graph, 'Image': desc_image, 'Table': desc_table, 'Tree': desc_tree,'Tab': desc_tab,
'TabGroup': desc_tabgroup, 'Button':desc_button, 'Button Types': desc_button_types,
'Popup':desc_popup, 'Popups':desc_popups, 'One Line Prog Meter':desc_one_line_progress_meter}
tab_text = [[sg.Column([[sg.T('This is sample text')],[ sg.Text(desc_text, font=('Consolas 12'))]])]]
tab_input = [[sg.Column([[sg.Input(size=(15,1))],[sg.Text(desc_inputtext, font=('Consolas 12'))]])]]
tab_checkbox = [[sg.Column([[sg.Checkbox('Checkbox', size=(15,1))],[sg.Text(desc_checkbox, font=('Consolas 12'))]])]]
tab_radio = [[sg.Column([[sg.Radio('Radio Button', group_id=1, size=(15,1))],[sg.Text(desc_radio, font=('Consolas 12'))]])]]
tab_listbox = [[sg.Column([[sg.Listbox(values=[1,2,3,4] ,size=(15,4))],[sg.Text(desc_listbox, font=('Consolas 12'))]])]]
tab_slider = [[sg.Column([[sg.Slider((1,100), orientation='h', size=(15,15))],[sg.Text(desc_slider, font=('Consolas 12'))]])]]
tab_spinner = [[sg.Column([[sg.Spin((1,2,3,4,5),initial_value=1,size=(15,1))],[sg.Text(desc_spin, font=('Consolas 12'))]])]]
tab_multiline = [[sg.Column([[sg.Multiline(size=(15,1))],[sg.Text(desc_multiline, font=('Consolas 12'))]])]]
tab_output= [[sg.Column([[sg.Text(desc_output, font=('Consolas 12'))]])]]
tab_progressbar = [[sg.Column([[sg.Text(desc_progressbar, font=('Consolas 12'))]])]]
tab_optionmenu = [[sg.Column([[sg.OptionMenu([1,2,3,4,5], size=(15,1))],[sg.Text(desc_inputoptionmenu, font=('Consolas 12'))]])]]
tab_combo = [[sg.Column([[sg.Combo([1,2,3,4,5], size=(15,1))],[sg.Text(desc_inputcombo, font=('Consolas 12'))]])]]
tab_frame = [[sg.Column([[sg.Frame('Frame',[[sg.T(' ')]], size=(15,1))],[sg.Text(desc_frame, font=('Consolas 12'))]])]]
tab_column = [[sg.Text(desc_column, font=('Consolas 12'))]]
tab_graph = [[sg.Text(desc_graph, font=('Consolas 12'))]]
tab_tab = [[sg.Text(desc_tab, font=('Consolas 12'))]]
tab_tabgroup = [[sg.Text(desc_tabgroup, font=('Consolas 12'))]]
tab_image = [[sg.Text(desc_image, font=('Consolas 12'))]]
tab_table = [[sg.Text(desc_table, font=('Consolas 12'))]]
tab_tree = [[sg.Text(desc_tree, font=('Consolas 12'))]]
tab_menu = [[sg.Text(desc_menu, font=('Consolas 12'))]]
tab_button = [[sg.Text(desc_button, font=('Consolas 12'))]]
tab_button_types = [[sg.Text(desc_button_types, font=('Consolas 12'))]]
tab_popup = [[sg.Text(desc_popup, font=('Consolas 12'))]]
tab_popups = [[sg.Text(desc_popups, font=('Consolas 12'))]]
tab_one_line_prog_meter = [[sg.Text(desc_one_line_progress_meter, font=('Consolas 12'))]]
tab_window = [[ sg.TabGroup([[sg.Tab('Parms',[[sg.Text(desc_window, font=('Consolas 12'))]]),
sg.Tab('Methods', [[sg.Column([[sg.Text(desc_window_methods)]], size=(500,500), scrollable=True, )]])]])]]
layout = [[sg.TabGroup([[sg.Tab('Window',tab_window),
sg.Tab('Text',tab_text),
sg.Tab('InputText', tab_input),
sg.Tab('Checkbox', tab_checkbox),
sg.Tab('Radio',tab_radio),
sg.Tab('Listbox', tab_listbox),
sg.Tab('Slider', tab_slider),
sg.Tab('Spinner',tab_spinner),
sg.Tab('Multiline', tab_multiline),
sg.Tab('OptionMenu', tab_optionmenu),
sg.Tab('Combo', tab_combo),
sg.Tab('Image', tab_image),
sg.Tab('Output', tab_output),
sg.Tab('Table', tab_table),
sg.Tab('Tree', tab_tree),
sg.Tab('Graph', tab_graph),
sg.Tab('ProgressBar', tab_progressbar),
sg.Tab('Frame', tab_frame),
sg.Tab('Column', tab_column),
sg.Tab('Tab', tab_tab),
sg.Tab('TabGroup', tab_tabgroup),
sg.Tab('Menu', tab_menu),
sg.Tab('Button', tab_button),
sg.Tab('Button Types', tab_button_types),
sg.Tab('Popup', tab_popup),
sg.Tab('Popups', tab_popups),
sg.Tab('One Line Prog Meter', tab_one_line_prog_meter),
]], tab_location='lefttop', title_color='blue', selected_title_color='red', key='_TABS_')],
[sg.Button('Copy')] ]
# layout = [[sg.Text('The PySimpleGUI SDK Quick Reference Guide', font='Any 15', relief=sg.RELIEF_RAISED)],
# [sg.Listbox(values=element_list, size=(15, len(element_list) + 2), key='_in_', change_submits=True,
# font=('Consolas 12')),
# sg.Text(desc_text, size=(55, 25), font=('Consolas 13'), text_color='darkblue', key='_out_')]]
window = sg.Window('PySimpleGUI SDK Quick Reference',
font='Consolas 12',
).Layout(layout)
while True:
event, values = window.Read()
if event is None or event == 'Exit':
break
elif event == 'Methods':
sg.PopupScrolled(desc_window_methods, size=(50,20))
elif event == 'Copy':
tab = values['_TABS_']
r = Tk()
r.withdraw()
r.clipboard_clear()
r.clipboard_append(descriptions[tab])
r.update() # now it stays on the clipboard after the window is closed
r.destroy()
# element = values['_in_'][0]
# try:
# desc = descriptions[element]
# except:
# desc = ''
# window.FindElement('_out_').Update(desc)
# print(button, values)

View File

@ -0,0 +1,45 @@
import PySimpleGUI as sg
sg.ChangeLookAndFeel('GreenTan')
col1 = sg.Column([[sg.Text('in pane1', text_color='blue')],
[sg.T('Pane1')],
[sg.T('Pane1')],
])
col2 = sg.Column([[sg.Text('in pane2', text_color='red')],
[sg.T('Pane2')],
[sg.Input(key='_IN2_', do_not_clear=True)],
[sg.T('Pane2')],
[sg.T('Pane2')],
], key='_COL2_', visible=False)
col3 = sg.Column([[sg.Text('in pane 4', text_color='green')],
[sg.In(key='_IN3_', enable_events=True, do_not_clear=True)],
], key='_COL3_', visible=False)
col4 = sg.Column([[sg.Text('Column 4', text_color='firebrick')],
[sg.In()],
], key='_COL4_')
col5 = sg.Column([[sg.Frame('Frame', [[sg.Text('Column 5', text_color='purple')],
[sg.In()],
])]])
layout = [ [sg.Text('Click'), sg.Text('', key='_OUTPUT_')],
[sg.Button('Remove'), sg.Button('Add')],
[sg.Pane([col5, sg.Column([[sg.Pane([col1, col2, col4], handle_size=15, orientation='v', background_color='red', show_handle=True, visible=True, key='_PANE_', border_width=0, relief=sg.RELIEF_GROOVE),]]),col3 ], orientation='h', background_color=None, size=(160,160), relief=sg.RELIEF_RAISED, border_width=0)]
]
window = sg.Window('Window Title', default_element_size=(15,1), resizable=True, border_depth=5).Layout(layout)
while True: # Event Loop
event, values = window.Read()
print(event, values)
if event is None or event == 'Exit':
break
if event == 'Remove':
window.Element('_COL2_').Update(visible=False)
window.Element('_COL3_').Update(visible=False)
elif event == 'Add':
window.Element('_COL2_').Update(visible=True)
window.Element('_COL3_').Update(visible=True)
window.Element('_IN2_').Update(values['_IN3_'])
window.Close()

View File

@ -1,23 +1,11 @@
#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import PySimpleGUI as sg
"""
Simple Form showing how to use keys on your input fields
"""
layout = [[sg.Text('Please enter your Name, Address, Phone')],
[sg.Text('Name', size=(10,1)), sg.InputText(key='-NAME-')],
[sg.Text('Address', size=(10,1)), sg.InputText(key='-ADDRESS-')],
[sg.Text('Phone', size=(10,1)), sg.InputText(key='-PHONE-')],
[sg.Button('Submit'), sg.Button('Cancel')]]
layout = [
[sg.Text('Please enter your Name, Address, Phone')],
[sg.Text('Name', size=(15, 1)), sg.InputText('1', key='name'), sg.FileBrowse()],
[sg.Text('Address', size=(15, 1)), sg.InputText('2', key='address')],
[sg.Text('Phone', size=(15, 1)), sg.InputText('3', key='phone')],
[sg.CloseButton('Submit'), sg.CloseButton('Cancel')]
]
window = sg.Window('Simple Data Entry Window').Layout(layout)
event, values = window.Read()
sg.Popup(event, values, values['name'], values['address'], values['phone'])
window = sg.Window('Simple Data Entry Window', layout)
event, values = window.read()
print(event, values['-NAME-'], values['-ADDRESS-'], values['-PHONE-'])

View File

@ -21,8 +21,8 @@ def DownloadSubtitlesGUI():
[sg.Text('Subtitle Grabber', size=(40, 1), font=('Any 15'))],
[sg.T('YouTube Link'),sg.In(default_text='',size=(60,1), key='link', do_not_clear=True) ],
[sg.Output(size=(90,20), font='Courier 12')],
[sg.ReadButton('Get List')],
[sg.T('Language Code'), combobox, sg.ReadButton('Download')],
[sg.Button('Get List')],
[sg.T('Language Code'), combobox, sg.Button('Download')],
[sg.Button('Exit', button_color=('white', 'firebrick3'))]
]