Demo updates with new theme calls

This commit is contained in:
PySimpleGUI 2019-12-24 18:52:47 -05:00
parent 52700b0780
commit 5484b047c0
96 changed files with 3530 additions and 228 deletions

View File

@ -5,15 +5,16 @@ Example of (almost) all widgets, that you can use in PySimpleGUI.
import PySimpleGUI as sg
sg.change_look_and_feel('GreenTan')
# sg.theme('Dark Red')
# sg.theme('Default1')
# sg.set_options(text_color='black', background_color='#A6B2BE', text_element_background_color='#A6B2BE')
# ------ Menu Definition ------ #
menu_def = [['&File', ['&Open', '&Save', 'E&xit', 'Properties']],
['&Edit', ['Paste', ['Special', 'Normal', ], 'Undo'], ],
['&Help', '&About...'], ]
# ------ Column Definition ------ #
column1 = [[sg.Text('Column 1', background_color='lightblue', justification='center', size=(10, 1))],
column1 = [[sg.Text('Column 1', justification='center', size=(10, 1))],
[sg.Spin(values=('Spin Box 1', '2', '3'),
initial_value='Spin Box 1')],
[sg.Spin(values=('Spin Box 1', '2', '3'),
@ -30,13 +31,10 @@ layout = [
[sg.CBox('Checkbox', size=(10, 1)),
sg.CBox('My second checkbox!', default=True)],
[sg.Radio('My first Radio! ', "RADIO1", default=True, size=(10, 1)),
sg.Radio('My second Radio!', "RADIO1")]], title='Options',
title_color='red',
relief=sg.RELIEF_SUNKEN,
tooltip='Use these to set flags')],
sg.Radio('My second Radio!', "RADIO1")]], title='Options', relief=sg.RELIEF_SUNKEN, tooltip='Use these to set flags')],
[sg.MLine(default_text='This is the default Text should you decide not to type anything', size=(35, 3)),
sg.MLine(default_text='A second multi-line', size=(35, 3))],
[sg.Combo(('Combobox 1', 'Combobox 2'), size=(20, 1)),
[sg.Combo(('Combobox 1', 'Combobox 2'),default_value='Combobox 1', size=(20, 1)),
sg.Slider(range=(1, 100), orientation='h', size=(34, 20), default_value=85)],
[sg.OptionMenu(('Menu Option 1', 'Menu Option 2', 'Menu Option 3'))],
[sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'), size=(30, 3)),
@ -44,7 +42,7 @@ layout = [
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=25, tick_interval=25),
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=75),
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=10),
sg.Col(column1, background_color='lightblue')]])
sg.Col(column1)]])
],
[sg.Text('_' * 80)],
[sg.Text('Choose A Folder', size=(35, 1))],
@ -52,7 +50,7 @@ layout = [
sg.InputText('Default Folder'), sg.FolderBrowse()],
[sg.Submit(tooltip='Click to submit this form'), sg.Cancel()]]
window = sg.Window('Everything bagel', layout,
window = sg.Window('Everything bagel', layout, no_titlebar=True,
default_element_size=(40, 1), grab_anywhere=False)
event, values = window.read()

View File

@ -25,7 +25,7 @@ EDGE_OFFSET = 3
GRAPH_SIZE = (500,500)
DATA_SIZE = (500,500)
sg.change_look_and_feel('Light Brown 1')
sg.theme('Light Brown 1')
graph = sg.Graph(GRAPH_SIZE, (0,0), DATA_SIZE)

View File

@ -3,7 +3,7 @@ import PySimpleGUI as sg
# Turn off padding in order to get a really tight looking layout.
sg.change_look_and_feel('Dark')
sg.theme('Dark')
sg.set_options(element_padding=(0, 0))
layout = [[sg.Text('User:', pad=((3, 0), 0)), sg.OptionMenu(values=('User 1', 'User 2'), size=(20, 1)),

View File

@ -1,30 +1,31 @@
#!/usr/bin/env python
import winsound
import sys
import PySimpleGUI as sg
from random import randint
if not sys.platform.startswith('win'):
sg.popup_error('Sorry, you gotta be on Windows')
sys.exit(0)
sg.theme('Dark Blue 3')
# .WAV files that contain your click sounds. Put full path if not in your application's folder
click_sound = r'ButtonClick.wav'
click_sound1 = r'ButtonClick1.wav'
layout = [ [sg.Text('Temperature'), sg.T(' '*30), sg.Text(size=(8,1), key='-TEMP OUT-')],
[sg.Text('Set Temp'), sg.T(' '*8), sg.Input(size=(8,1), key='-IN-'), sg.T(' '*10), sg.Button('Set')],
[sg.Button('Off'), sg.T(' '*13), sg.Button('Turn relay on', button_color=('white', 'red')),sg.T(' '*5), sg.Button('Quit')] ]
sg.change_look_and_feel('Dark Blue 3') # because gray windows are boring
window = sg.Window('Temperature Manager', layout, font='Default -24', return_keyboard_events=True, no_titlebar=True)
# Your window's layout
layout = [ [sg.Text('Click a button to hear a click')],
[sg.Button('Click'), sg.Button('Another Click')]]
# Create your Window
window = sg.Window("Button Click", layout)
while True: # The Event Loops
event, values = window.read()
if event is None:
while True: # Event Loop
event, values = window.read(timeout=500) # returns every 500 ms
print(event, values) if event != sg.TIMEOUT_KEY else None # a debug print
if event in (None, 'Quit'):
break
if event == 'Click':
winsound.PlaySound(click_sound, 1)
elif event == 'Another Click':
winsound.PlaySound(click_sound1, 1)
if event == 'Set':
print('setting temperature to ', values['-IN-'])
window['-TEMP OUT-'].update(values['-IN-'] + ' C')
elif event.startswith('Turn'):
print('Turning on the relay')
elif event == 'Off':
print('Turning off sensor')
elif event.startswith('F11'):
window.maximize()
elif event.startswith('Escape'):
window.normal()
window['-TEMP OUT-'].update(str(randint(2,70)) + ' C')
window.close()

View File

@ -7,7 +7,7 @@ Shows how button states can be controlled by a user application. The program ma
states for buttons and changes the text color to show greyed-out (disabled) buttons
"""
sg.change_look_and_feel('Dark')
sg.theme('Dark')
sg.set_options(element_padding=(0, 0))
layout = [[sg.Text('User:', pad=((3, 0), 0)), sg.OptionMenu(values=('User 1', 'User 2'), size=(20, 1)), sg.Text('0', size=(8, 1))],

View File

@ -7,7 +7,7 @@ play = b'iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAABmJLR0QA/wD/AP+gvaeTAAA
stop = b'iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAABmJLR0QA/wD/AP+gvaeTAAAAaklEQVRoge3ZQQqAMAxFwSre/8p6AZFUiXzKzLqLPNJVOwYAvLcVzpztU9Q8zrr/NUW3Y+JsZXsdSjdimY0ISSMkjZA0QtIISSMkjZA0QtIISSMkjZA0QtIISSMkzcxrfMo/ya1lNgIAX1zq+ANHUjXZuAAAAABJRU5ErkJggg=='
eject = b'iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAABmJLR0QA/wD/AP+gvaeTAAAByklEQVRoge3YO2gUURSA4S+JRnyACIGADyxERAsb0UKrWIidWIidlSA2YpFWSauNVtrYiIU2YpFCLGwEEWwsBAsLEbFQFARFfKBZizkyK5pkZvZmZ7PeH05z595z/sPszpxdMplMJpMZbDZFLGsm8CxiomWXxqzBQ3QiHmNdq0YNGMc9RQOvIjqxNt6iVy1GcF0h/h47sR1vY+0mRluzq8ElhfBn7O9a34tPce1KC161OK8Q/Y7D/7h+EF9jz7k+etXilELwJ44vsO8ofsTeM33wqsURpdzZCvtPK5s+toRetZjCF4XYTI1zM3HmGw4lt6rJbnxQCF1tcP5ynP2IPQm9arENb0LkDsYa5BjFrcjxDjuS2VVkI16EwH2s6iHXStxVvjy39GxXkfV4Iu3Y0T3OPMWGBDkXZDUeRMHnmEyY+/eA2cEjrE2Y+w/GcDsKvcbWJaixGS+jxixWpC4wgmvK+WlX6gJddM9lN6J2Mi4q56cDKRPPwz7lXHYhVdJp5W+KtmK61yZOYG4AGpnDyV6byWT+ZxZ7Rnf6YlGdeX2XxZ8AVag6AiR9uzZg0U/G0NyR3MigUfU7MmhPr78YmjuSyWQymUxmmPgFokSdfYSQKDwAAAAASUVORK5CYII='
sg.change_look_and_feel('Light Green 3') # Set a color theme
sg.theme('Light Green 3') # Set a color theme
bg = sg.LOOK_AND_FEEL_TABLE[sg.CURRENT_LOOK_AND_FEEL]['BACKGROUND'] # Get the background for the current theme

View File

@ -50,7 +50,7 @@ def GraphicButton(text, key, image_data, color=DEF_BUTTON_COLOR, size=(100, 50))
def ShowMeTheButtons():
sg.change_look_and_feel('Black')
sg.theme('Black')
frame_layout = [[sg.Text('Who says Windows have to be ugly when using tkinter?', size=(45, 3))],
[sg.Text(

View File

@ -6,7 +6,7 @@ A simple send/response chat window. Add call to your send-routine and print the
If async responses can come in, then will need to use a different design that uses PySimpleGUI async design pattern
'''
sg.change_look_and_feel('GreenTan') # give our window a spiffy set of colors
sg.theme('GreenTan') # give our window a spiffy set of colors
layout = [[sg.Text('Your output will go here', size=(40, 1))],
[sg.Output(size=(110, 20), font=('Helvetica 10'))],

View File

@ -15,7 +15,7 @@ Special keyboard keys:
def ChatBotWithHistory():
# ------- Make a new Window ------- #
# give our form a spiffy set of colors
sg.change_look_and_feel('GreenTan')
sg.theme('GreenTan')
layout = [[sg.Text('Your output will go here', size=(40, 1))],
[sg.Output(size=(127, 30), font=('Helvetica 10'))],

View File

@ -13,7 +13,7 @@ to collect user input that is sent to the chatbot. The reply is displayed in th
# Create the 'Trainer GUI'
# The Trainer GUI consists of a lot of progress bars stacked on top of each other
sg.change_look_and_feel('GreenTan')
sg.theme('GreenTan')
# sg.DebugWin()
MAX_PROG_BARS = 20 # number of training sessions
bars = []

View File

@ -16,7 +16,7 @@ to collect user input that is sent to the chatbot. The reply is displayed in th
# Create the 'Trainer GUI'
# The Trainer GUI consists of a lot of progress bars stacked on top of each other
sg.change_look_and_feel('NeutralBlue')
sg.theme('NeutralBlue')
# sg.DebugWin()
MAX_PROG_BARS = 20 # number of training sessions
bars = []

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
import sys
import PySimpleGUI as sg
reverse = {}

View File

@ -662,7 +662,7 @@ def popup_color_chooser(look_and_feel=None):
old_look_and_feel = None
if look_and_feel is not None:
old_look_and_feel = sg.CURRENT_LOOK_AND_FEEL
sg.change_look_and_feel(look_and_feel)
sg.theme(look_and_feel)
button_size = (1, 1)
@ -697,12 +697,12 @@ def popup_color_chooser(look_and_feel=None):
color_chosen = event[1]
window.close()
if old_look_and_feel is not None:
sg.change_look_and_feel(old_look_and_feel)
sg.theme(old_look_and_feel)
return color_chosen
if __name__ == '__main__':
sg.change_look_and_feel('Light Brown 4')
sg.theme('Light Brown 4')
layout = [[sg.In(key='-CHOICE-'), sg.B('Color Picker')],
[sg.Ok(), sg.Cancel()]]
window = sg.Window('My application', layout)

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python
import PySimpleGUIQt as sg
import PySimpleGUI as sg
"""
@ -665,6 +665,7 @@ color_map = {
'YellowGreen': '#9ACD32',
}
sg.popup_quick_message('Building your table... one moment please...', background_color='red', text_color='white', font='Any 14')
sg.set_options(button_element_size=(12, 1),
element_padding=(0, 0),
@ -672,12 +673,8 @@ sg.set_options(button_element_size=(12, 1),
border_width=1, tooltip_time=100)
# start layout with the tittle
layout = [
[sg.Text('Hover mouse to see RGB value, click for white & black text',
justification='center',
text_color='blue', background_color='light green',
size=(100, 1), pad=(0, (0, 20)))]
]
layout = [[sg.Text('Hover mouse to see RGB value, click for white & black text',
justification='center', text_color='blue', background_color='light green', size=(90, 1), font='Default 14', pad=(0, (0, 20)))]]
# -- Create primary color viewer window --
color_list = [key for key in color_map]
@ -694,7 +691,7 @@ for rows in range(40):
layout.append(row)
window = sg.Window('Color Viewer', layout, grab_anywhere=False, font=('any 9'), element_padding=(0,0), border_depth=0)
window = sg.Window('Color Viewer', layout, font='Any 9', element_padding=(0,0), border_depth=0)
# -- Event loop --
while True:

View File

@ -1,16 +1,6 @@
# this one long import has the effect of making the code more compact as there is no 'sg.' prefix required for Elements
import PySimpleGUI as sg
from PySimpleGUI import InputCombo, Combo, Multiline, ML,
MLine, Checkbox, CB, Check,
Button, B, Btn, ButtonMenu,
Canvas, Column, Col, Combo,
Frame, Graph, Image, InputText,
Input, In, Listbox, LBox, Menu,
Multiline, ML, MLine, OptionMenu,
Output, Pane, ProgressBar, Radio,
Slider, Spin, StatusBar, Tab,
TabGroup, Table, Text, Txt, T,
Tree, TreeData, VerticalSeparator, Window, Sizer
from PySimpleGUI import InputCombo, Combo, Multiline, ML, MLine, Checkbox, CB, Check, Button, B, Btn, ButtonMenu, Canvas, Column, Col, Combo, Frame, Graph, Image, InputText, Input, In, Listbox, LBox, Menu, Multiline, ML, MLine, OptionMenu, Output, Pane, ProgressBar, Radio, Slider, Spin, StatusBar, Tab, TabGroup, Table, Text, Txt, T, Tree, TreeData, VerticalSeparator, Window, Sizer
"""
Demo Columns and Frames
@ -22,7 +12,7 @@ from PySimpleGUI import InputCombo, Combo, Multiline, ML,
There are 3 columns. Two are side by side at the top and the third is along the bottom
"""
sg.change_look_and_feel('GreenTan')
sg.theme('GreenTan')
col2 = Column([[Frame('Accounts:', [[Column([[Listbox(['Account '+str(i) for i in range(1, 16)],
key='-ACCT-LIST-', size=(15, 20)), ]], size=(150, 400))]])]], pad=(0, 0))

View File

@ -5,7 +5,7 @@ import PySimpleGUI as sg
Usage of Column Element
'''
sg.change_look_and_feel('BlueMono')
sg.theme('BlueMono')
css = {'text_color': 'white', 'background_color': 'blue'}
# Column layout

View File

@ -5,7 +5,7 @@ import PySimpleGUI as sg
Simple "diff" in PySimpleGUI
'''
sg.change_look_and_feel('Dark Blue 3')
sg.theme('Dark Blue 3')
def GetFilesToCompare():
form_rows = [[sg.Text('Enter 2 files to comare')],

View File

@ -142,7 +142,7 @@ class GameOfLife:
line_color='black', fill_color='yellow')
event, values = self.window.read(timeout=self.delay)
if event in (None, '-DONE-'):
return
exit()
self.delay = values['-SLIDER-']
self.T = int(values['-SLIDER2-'])
self.window['-S1-OUT-'].update(values['-SLIDER-'])

View File

@ -12,7 +12,7 @@ import webbrowser
# Here is a more complete list of cursors you can choose from
cursors = ('X_cursor', 'no', 'arrow','based_arrow_down','based_arrow_up','boat','bogosity','bottom_left_corner','bottom_right_corner','bottom_side','bottom_tee','box_spiral','center_ptr','circle','clock','coffee_mug','cross','cross_reverse','crosshair','diamond_cross','dot','dotbox','double_arrow','draft_large','draft_small','draped_box','exchange','fleur','gobbler','gumby','hand1','hand2','heart','icon','iron_cross','left_ptr','left_side','left_tee','leftbutton','ll_angle','lr_angle','man','middlebutton','mouse','no','pencil','pirate','plus','question_arrow','right_ptr','right_side','right_tee','rightbutton','rtl_logo','sailboat','sb_down_arrow','sb_h_double_arrow','sb_left_arrow','sb_right_arrow','sb_up_arrow','sb_v_double_arrow','shuttle','sizing','spider','spraycan','star','target','tcross','top_left_arrow','top_left_corner','top_right_corner','top_side','top_tee','trek','ul_angle','umbrella','ur_angle','watch','xterm','arrow','center_ptr','crosshair','fleur','ibeam','icon','sb_h_double_arrow','sb_v_double_arrow','watch','xterm','no','starting','size','size_ne_sw','size_ns','size_nw_se','size_we','uparrow','wait','arrow','cross','crosshair','ibeam','plus','watch','xterm')
sg.change_look_and_feel('Light Blue 2')
sg.theme('Light Blue 2')
layout = [ [sg.Text('Here is a clickable link for you')],
[sg.Text('Notice how the cursor switches to a "hand" when hover over the link')],
@ -21,18 +21,16 @@ layout = [ [sg.Text('Here is a clickable link for you')],
[sg.Text('watch - This makes the spinning-donut-of-death cursor on Windows', key='-WATCH-')],
[sg.Text('fleur - The "Move" cursor', key='-FLEUR-')],
[sg.Text('trek - Beam me up Scotty!', key='-TREK-')],
# [sg.Text('watch -', key='-WATCH-')],
# [sg.Text('watch -', key='-WATCH LEFT-')],
[sg.Button('Exit')] ]
window = sg.Window('Window Title', layout, finalize=True)
# Directly interact with the tkinter widget, changing the cursor shown when placed cursor is over this element
window['-LINK-'].Widget.config(cursor='hand2')
window['-WATCH-'].Widget.config(cursor='watch')
window['-FLEUR-'].Widget.config(cursor='fleur')
window['-TREK-'].Widget.config(cursor='trek')
window['Exit'].Widget.config(cursor='no')
window['-LINK-'].set_cursor(cursor='hand2')
window['-WATCH-'].set_cursor(cursor='watch')
window['-FLEUR-'].set_cursor(cursor='fleur')
window['-TREK-'].set_cursor(cursor='trek')
window['Exit'].set_cursor(cursor='no')
while True: # Event Loop
event, values = window.read()

View File

@ -8,10 +8,11 @@ import PySimpleGUI as sg
3. There is a safeguard to stop from launching multiple copies of window2. Only 1 window2 is visible at a time
"""
sg.theme('Dark Blue 3')
# Window 1 layout
layout = [
[sg.Text('This is the FIRST WINDOW'), sg.Text(' ', key='-OUTPUT-')],
[sg.Text('')],
[sg.Text()],
[sg.Button('Launch 2nd Window'), sg.Button('Popup'), sg.Button('Exit')]
]
@ -31,8 +32,8 @@ while True: # Event Loop
win2_active = True
# window 2 layout - note - must be "new" every time a window is created
layout2 = [
[sg.Text('The second window'), sg.Text('', key='-OUTPUT-')],
[sg.Input('', key='-IN-')],
[sg.Text('The second window')],
[sg.Input(key='-IN-')],
[sg.Button('Show'), sg.Button('Exit')]
]
window2 = sg.Window('Second Window', layout2)

View File

@ -8,13 +8,14 @@ import PySimpleGUI as sg
# Design pattern 2 - First window remains active
layout = [[ sg.Text('Window 1'),],
[sg.Input('')],
[sg.Input()],
[sg.Text('', size=(20,1), key='-OUTPUT-')],
[sg.Button('Launch 2'), sg.Button('Exit')]]
window1 = sg.Window('Window 1', layout)
window2_active = False
while True:
event1, values1 = window1.read(timeout=100)
window1['-OUTPUT-'].update(values1[0])

View File

@ -5,7 +5,7 @@ import PySimpleGUI as sg
'''
layout = [[sg.Text('Window 1'), ],
[sg.Input('')],
[sg.Input()],
[sg.Text('',size=(20,1), key='-OUTPUT-')],
[sg.Button('Next >'), sg.Button('Exit')]]

View File

@ -11,7 +11,7 @@ These are the accepted design patterns that cover the two primary use cases
# ---------------------------------#
import PySimpleGUI as sg
sg.change_look_and_feel('Dark Blue 3')
sg.theme('Dark Blue 3')
layout = [[ sg.Text('My Oneshot') ],
[ sg.Button('OK') ]]
@ -26,7 +26,7 @@ window.close()
# -------------------------------------#
import PySimpleGUI as sg
sg.change_look_and_feel('Dark Blue 3')
sg.theme('Dark Blue 3')
layout = [[ sg.Text('My layout', text_color='red') ],
[ sg.Input(key='-INPUT-')],
@ -45,7 +45,7 @@ window.close()
# ------------------------------------------------------------------#
import PySimpleGUI as sg
sg.change_look_and_feel('Dark Blue 3')
sg.theme('Dark Blue 3')
layout = [[ sg.Text('My layout', key='-TEXT-KEY-') ],
[ sg.Button('OK'), sg.Button('Cancel') ]]

View File

@ -19,7 +19,7 @@ ROOT_PATH = './'
def Launcher():
sg.change_look_and_feel('Dark')
sg.theme('Dark')
namesonly = [f for f in os.listdir(ROOT_PATH) if f.endswith('.py')]

View File

@ -54,7 +54,7 @@ def main():
num_cores = len(psutil.cpu_percent(percpu=True)) # get the number of cores in the CPU
sg.change_look_and_feel('Black')
sg.theme('Black')
sg.set_options(element_padding=(0,0), margins=(1,1), border_width=0)
# the clever Red X graphic

View File

@ -33,7 +33,7 @@ def main():
global g_exit, g_response_time
# start ping measurement thread
sg.change_look_and_feel('Black')
sg.theme('Black')
sg.set_options(element_padding=(0, 0))
layout = [

View File

@ -40,7 +40,7 @@ def main():
global g_interval, g_procs, g_exit
# ---------------- Create Form ----------------
sg.change_look_and_feel('Black')
sg.theme('Black')
layout = [
[sg.Text('', size=(8, 1), font=('Helvetica', 20),
text_color=sg.YELLOWS[0], justification='center', key='text')],

View File

@ -5,7 +5,7 @@ import psutil
# Yet another usage of CPU data
# ---------------- Create Form ----------------
sg.change_look_and_feel('Black')
sg.theme('Black')
layout = [[sg.Text('CPU Utilization')],
[sg.Text('', size=(8, 2), font=('Helvetica', 20),

View File

@ -20,7 +20,7 @@ MAX_EMAILS = 10
def gui():
sg.change_look_and_feel('Topanga')
sg.theme('Topanga')
sg.set_options(border_width=0, margins=(0, 0), element_padding=(4, 0))
color = ('#282923', '#282923')
layout = [[sg.Text('Email New Mail Notification' + 48 * ' '),

View File

@ -20,7 +20,7 @@ def time_as_int():
# ---------------- Create Form ----------------
sg.change_look_and_feel('Black')
sg.theme('Black')
layout = [[sg.Text('')],
[sg.Text('', size=(8, 2), font=('Helvetica', 20),

View File

@ -56,7 +56,7 @@ def human_size(bytes, units=[' bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB']):
def main():
# ---------------- Create Window ----------------
sg.change_look_and_feel('Black')
sg.theme('Black')
sg.set_options(element_padding=(0, 0), margins=(1, 1), border_width=0)
def GraphColumn(name, key):

View File

@ -5,7 +5,7 @@ import PySimpleGUI as sg
Usage of Disable elements
'''
sg.change_look_and_feel('Dark')
sg.theme('Dark')
sg.set_options(element_padding=(0, 0))
layout = [

View File

@ -9,7 +9,7 @@ import os
'''
def Launcher():
sg.change_look_and_feel('LightGreen')
sg.theme('LightGreen')
layout = [[sg.Text('PyInstaller EXE Creator', font='Any 15')],
[sg.Text('Source Python File'), sg.Input(key='-sourcefile-', size=(45, 1)),

View File

@ -61,7 +61,7 @@ def send_an_email(from_address, to_address, subject, message_text, user, passwor
'''
def main():
sg.change_look_and_feel('Dark Blue 3')
sg.theme('Dark Blue 3')
layout = [[sg.Text('Send an Email', font='Default 18')],
[sg.T('From:', size=(8,1)), sg.Input(key='-EMAIL FROM-', size=(35,1))],
[sg.T('To:', size=(8,1)), sg.Input(key='-EMAIL TO-', size=(35,1))],

View File

@ -12,7 +12,7 @@ import PySimpleGUI as sg
Second parameter for windows is an entire key, for elements is something added onto a key. This key or modified key is what is returned when you read the window.
If the key modifier is text and the key is text, then the key returned from the read will be the 2 concatenated together. Otherwise your event will be a tuple containing the key_modifier value you pass in and the key belonging to the element the event happened to.
"""
sg.change_look_and_feel('Dark Blue 3')
sg.theme('Dark Blue 3')
layout = [ [sg.Text('Move mouse over me', key='-TEXT-')],
[sg.In(key='-IN-')],

View File

@ -6,7 +6,7 @@ import PySimpleGUI as sg
'''
def main():
sg.change_look_and_feel('TanBlue')
sg.theme('TanBlue')
column1 = [
[sg.Text('Column 1', background_color=sg.DEFAULT_BACKGROUND_COLOR,

View File

@ -12,7 +12,7 @@ root.destroy()
Showing fonts in PSG / tk
'''
sg.change_look_and_feel('Black')
sg.theme('Black')
layout = [[sg.Text('My Text Element',
size=(20, 1),

View File

@ -0,0 +1,32 @@
#!/usr/bin/env python
import PySimpleGUI as sg
from random import randint
def Battleship():
sg.theme('Dark Blue 3')
MAX_ROWS = MAX_COL = 10
# Start building layout with the top 2 rows that contain Text elements
layout = [[sg.Text('BATTLESHIP', font='Default 25')],
[sg.Text(size=(15,1), key='-MESSAGE-', font='Default 20')]]
# Add the board, a grid a buttons
layout += [[sg.Button(str('O'), size=(4, 2), pad=(0,0), border_width=0, key=(row,col)) for col in range(MAX_COL)] for row in range(MAX_ROWS)]
# Add the exit button as the last row
layout += [[sg.Button('Exit', button_color=('white', 'red'))]]
window = sg.Window('Battleship', layout)
while True: # The Event Loop
event, values = window.read()
print(event, values)
if event in (None, 'Exit'):
break
if randint(1,10) < 5: # simulate a hit or a miss
window[event].update('H', button_color=('white','red'))
window['-MESSAGE-'].update('Hit')
else:
window[event].update('M', button_color=('white','black'))
window['-MESSAGE-'].update('Miss')
window.close()
Battleship()

View File

@ -0,0 +1,41 @@
#!/usr/bin/env python
import PySimpleGUI as sg
from random import randint
def Battleship():
sg.theme('Dark Blue 3')
MAX_ROWS = MAX_COL = 10
# Start building layout with the top 2 rows that contain Text elements
layout = [[sg.Text('BATTLESHIP', font='Default 25')],
[sg.Text(size=(15,1), key='-MESSAGE-', font='Default 20')]]
# Build the "board", a grid of Buttons
board = []
for row in range(MAX_ROWS):
layout_row = []
for col in range(MAX_COL):
layout_row.append(sg.Button(str('O'), size=(4, 2), pad=(0,0), border_width=0, key=(row,col)))
board.append(layout_row)
# Add the board to the layout
layout += board
# Add the exit button as the last row
layout += [[sg.Button('Exit', button_color=('white', 'red'))]]
window = sg.Window('Battleship', layout)
while True: # The Event Loop
event, values = window.read()
print(event, values)
if event in (None, 'Exit'):
break
if randint(1,10) < 5: # simulate a hit or a miss
window[event].update('H', button_color=('white','red'))
window['-MESSAGE-'].update('Hit')
else:
window[event].update('M', button_color=('white','black'))
window['-MESSAGE-'].update('Miss')
window.close()
Battleship()

View File

@ -0,0 +1,35 @@
#!/usr/bin/env python
import PySimpleGUI as sg
from random import randint
def Battleship():
sg.theme('Dark Blue 3')
MAX_ROWS = MAX_COL = 10
# Start building layout with the top 2 rows that contain Text elements
layout = [[sg.Text('BATTLESHIP', font='Default 25')],
[sg.Text(size=(15,1), key='-MESSAGE-', font='Default 20')]]
# Build the "board", a grid of Buttons
board = []
for row in range(MAX_ROWS):
board.append([sg.Button(str('O'), size=(4, 2), pad=(0,0), border_width=0, key=(row,col)) for col in range(MAX_COL)])
# Add the board and the exit button to the layout
layout += board
# Add the exit button as the last row
layout += [[sg.Button('Exit', button_color=('white', 'red'))]]
window = sg.Window('Battleship', layout)
while True: # The Event Loop
event, values = window.read()
print(event, values)
if event in (None, 'Exit'):
break
if randint(1,10) < 5: # simulate a hit or a miss
window[event].update('H', button_color=('white','red'))
window['-MESSAGE-'].update('Hit')
else:
window[event].update('M', button_color=('white','black'))
window['-MESSAGE-'].update('Miss')
window.close()
Battleship()

View File

@ -8,24 +8,25 @@ import PySimpleGUI as sg
see in things like editors
"""
# image_file = r'Color-names.png'
image_file = None # image is optional
# image_file = None # image is optional
image_file = r'C:\Python\PycharmProjects\GooeyGUI\logo200.png' # image is optional
layout = [[sg.Graph(
canvas_size=(400, 400),
graph_bottom_left=(0, 400),
graph_top_right=(400, 0),
key="-GRAPH-",
change_submits=True, # mouse click events
drag_submits=True),],
[sg.Text(key='info', size=(60, 1))]]
canvas_size=(400, 400),
graph_bottom_left=(0, 0),
graph_top_right=(400, 400),
key="-GRAPH-",
change_submits=True, # mouse click events
background_color='lightblue',
drag_submits=True), ],
[sg.Text(key='info', size=(60, 1))]]
window = sg.Window("draw rect on image", layout, finalize=True)
# get the graph element for ease of use later
graph = window["-GRAPH-"] # type: sg.Graph
graph = window["-GRAPH-"] # type: sg.Graph
graph.draw_image(image_file, location=(0,0)) if image_file else None
graph.draw_image(image_file, location=(0,400)) if image_file else None
dragging = False
start_point = end_point = prior_rect = None
@ -34,8 +35,8 @@ while True:
if event is None:
break # exit
if event == "-GRAPH-": # if there's a "Graph" event, then it's a mouse
if event == "-GRAPH-": # if there's a "Graph" event, then it's a mouse
x, y = values["-GRAPH-"]
if not dragging:
start_point = (x, y)
@ -46,12 +47,12 @@ while True:
graph.delete_figure(prior_rect)
if None not in (start_point, end_point):
prior_rect = graph.draw_rectangle(start_point, end_point, line_color='red')
elif event.endswith('+UP'): # The drawing has ended because mouse up
elif event.endswith('+UP'): # The drawing has ended because mouse up
info = window["info"]
info.update(value=f"grabbed rectangle from {start_point} to {end_point}")
start_point, end_point = None, None # enable grabbing a new rect
start_point, end_point = None, None # enable grabbing a new rect
dragging = False
else:
print("unhandled event", event, values)

View File

@ -3,7 +3,7 @@ import PySimpleGUI as sg
# Usage of Graph element.
layout = [[sg.Graph(canvas_size=(400, 400), graph_bottom_left=(0, 0), graph_top_right=(400, 400), background_color='red', key='graph')],
layout = [[sg.Graph(canvas_size=(400, 400), graph_bottom_left=(0, 0), graph_top_right=(400, 400), background_color='red', enable_events=True, key='graph')],
[sg.Text('Change circle color to:'), sg.Button('Red'), sg.Button('Blue'), sg.Button('Move')]]
window = sg.Window('Graph test', layout, finalize=True)
@ -17,6 +17,7 @@ line = graph.draw_line((0, 0), (100, 100))
arc = graph.draw_arc((0, 0), (400, 400), 160, 10, style='arc', arc_color='blue')
while True:
event, values = window.read()
print(event, values)
if event is None:
break
if event in ('Blue', 'Red'):

View File

@ -27,7 +27,7 @@ def main():
thread = Thread(target=ping_thread, args=(None,))
thread.start()
sg.change_look_and_feel('Black')
sg.theme('Black')
sg.set_options(element_padding=(0, 0))
layout = [

View File

@ -23,6 +23,7 @@ def draw_axis():
if y != 0:
graph.draw_text(str(y), (-10, y), color='blue')
sg.theme('DarkAmber')
# Create the graph that will be put into the window
graph = sg.Graph(canvas_size=(400, 400),

View File

@ -7,7 +7,7 @@ import sys
Example of random line in Graph element.
'''
sg.change_look_and_feel('black')
sg.theme('black')
STEP_SIZE = 1
SAMPLES = 300
@ -32,7 +32,7 @@ def main():
# start ping measurement thread
sg.change_look_and_feel('Black')
sg.theme('Black')
sg.set_options(element_padding=(0, 0))
layout = [[sg.Button('Quit', button_color=('white', 'black'))],
@ -75,7 +75,6 @@ def main():
graph.move_figure(figure, -STEP_SIZE, 0)
prev_x = prev_x - STEP_SIZE
# print(f'io={i} {prev_x,prev_y} to {new_x, new_y}')
last_figure = graph.draw_line((prev_x, prev_y), (new_x, new_y), color='white')
figures.append(last_figure)
prev_x, prev_y = new_x, new_y

View File

@ -27,7 +27,7 @@ def main():
thread = Thread(target=ping_thread, args=(None,))
thread.start()
sg.change_look_and_feel('Black')
sg.theme('Black')
sg.set_options(element_padding=(0, 0))
layout = [[sg.Text('Ping times to Google.com', font='Any 12'),

View File

@ -21,7 +21,7 @@ def HowDoI():
'''
# ------- Make a new Window ------- #
# give our form a spiffy set of colors
sg.change_look_and_feel('GreenTan')
sg.theme('GreenTan')
layout = [
[sg.Text('Ask and your answer will appear here....', size=(40, 1))],

View File

@ -0,0 +1,52 @@
import PySimpleGUI as sg
'''
IP Address entry window with digit validation and auto advance
If not a digit or ., the ignored
. will advance the focus to the next entry
On the last input, once it's complete the focus moves to the OK button
Pressing spacebar with focus on OK generates an -OK- event
'''
# create a short-cut element so don't have to type this in over and over
def MyInput(key): return sg.I('', size=(3, 1), key=key, pad=(0, 2))
layout = [[sg.T('Your typed chars appear here:'), sg.T('', key='-OUTPUT-')],
[MyInput(0), sg.T('.'), MyInput(1), sg.T('.'),
MyInput(2), sg.T('.'), MyInput(3)],
[sg.B('Ok', key='-OK-', bind_return_key=True), sg.B('Exit')]]
window = sg.Window('Window Title', layout, return_keyboard_events=True)
while True: # Event Loop
event, values = window.read()
print(event)
if event is None or event == 'Exit':
break
elem = window.find_element_with_focus()
if elem is not None:
key = elem.Key
# get value of input field that has focus
value = values[key]
if event == '.' and key != '-OK-': # if a ., then advance to next field
elem.update(value[:-1])
value = value[:-1]
next_elem = window[key+1]
next_elem.set_focus()
elif event not in '0123456789':
elem.update(value[:-1])
elif len(value) > 2 and key < 3: # if 2 digits typed in, move on to next input
next_elem = window[key+1]
next_elem.set_focus()
elif len(value) > 2 and key == 3:
window['-OK-'].set_focus()
print('You entered IP Address {}.{}.{}.{}'.format(*values.values()))
window.close()

View File

@ -10,6 +10,8 @@ PLAYER_COMMAND_PAUSE = 2
PLAYER_COMMAND_NEXT = 3
PLAYER_COMMAND_RESTART_SONG = 4
helv15 = 'Helvetica 15'
# ---------------------------------------------------------------------- #
# PlayerGUI CLASS #
# ---------------------------------------------------------------------- #

View File

@ -846,7 +846,7 @@ fig_dict = {'Pyplot Simple':PyplotSimple, 'Pyplot Formatstr':PyplotFormatstr,'Py
'Pyplot Scatter With Legend' :PyplotScatterWithLegend, 'Artist Customized Box Plots' : PyplotArtistBoxPlots,
'Artist Customized Box Plots 2' : ArtistBoxplot2, 'Pyplot Histogram' : PyplotHistogram}
sg.change_look_and_feel('LightGreen')
sg.theme('LightGreen')
figure_w, figure_h = 650, 650
# define the form layout

View File

@ -865,7 +865,7 @@ fig_dict = {'Pyplot Simple': PyplotSimple, 'Pyplot Formatstr': PyplotFormatstr,
'Artist Customized Box Plots 2': ArtistBoxplot2, 'Pyplot Histogram': PyplotHistogram}
sg.change_look_and_feel('LightGreen')
sg.theme('LightGreen')
figure_w, figure_h = 650, 650
# define the form layout
listbox_values = list(fig_dict)

View File

@ -1,4 +1,6 @@
from matplotlib import use
import PySimpleGUI as sg
# import PySimpleGUIQt as sg; use('qt5agg')
import matplotlib.pyplot as plt
"""
@ -8,8 +10,12 @@ import matplotlib.pyplot as plt
It turns out to be a rather simple thing to do. The secret is to add parameter block=False to plt.show()
"""
def draw_plot():
plt.plot([0.1, 0.2, 0.5, 0.7])
plt.show(block=False)
layout = [[sg.Button('Plot'), sg.Cancel(), sg.Button('Popup')]]
window = sg.Window('Have some Matplotlib....', layout)
while True:
@ -17,9 +23,7 @@ while True:
if event in (None, 'Cancel'):
break
elif event == 'Plot':
history = [0.1, 0.2, 0.5, 0.7]
plt.plot(history)
plt.show(block=False)
draw_plot()
elif event == 'Popup':
sg.popup('Yes, your application is still running')
window.close()

View File

@ -13,10 +13,10 @@ from sys import platform as PLATFORM
#------- GUI definition & setup --------#
sg.change_look_and_feel('DarkBlue')
sg.theme('DarkBlue')
def btn(name): # a PySimpleGUI "User Defined Element" (see docs)
return sg. Button(name, size=(6, 1), pad=(1, 1))
return sg.Button(name, size=(6, 1), pad=(1, 1))
layout = [[sg.Input(default_text='Video URL or Local Path:', size=(30, 1), key='-VIDEO_LOCATION-'), sg.Button('load')],
[sg.Image('', size=(300, 170), key='-VID_OUT-')],

View File

@ -20,40 +20,43 @@ def second_window():
def test_menus():
sg.change_look_and_feel('LightGreen')
sg.theme('LightGreen')
sg.set_options(element_padding=(0, 0))
# ------ Menu Definition ------ #
menu_def = [['&File', ['&Open', '&Save', '&Properties', 'E&xit']],
menu_def = [['&File', ['&Open Ctrl-O', '&Save Ctrl-S', '&Properties', 'E&xit']],
['&Edit', ['&Paste', ['Special', 'Normal', ], 'Undo'], ],
['&Toolbar', ['---', 'Command &1', 'Command &2',
'---', 'Command &3', 'Command &4']],
['&Help', '&About...'], ]
right_click_menu = ['Unused', ['Right', '!&Click', '&Menu', 'E&xit', 'Properties']]
# ------ GUI Defintion ------ #
layout = [
[sg.Menu(menu_def, tearoff=False, pad=(20, 1))],
[sg.Menu(menu_def, tearoff=False, pad=(200, 1))],
[sg.Text('Right click me for a right click menu example')],
[sg.Output(size=(60, 20))],
[sg.ButtonMenu('ButtonMenu', right_click_menu, key='-BMENU-'), sg.Button('Plain Button')],
]
window = sg.Window("Windows-like program",
layout,
default_element_size=(12, 1),
auto_size_text=False,
auto_size_buttons=False,
default_button_element_size=(12, 1))
default_button_element_size=(12, 1),
right_click_menu=right_click_menu)
# ------ Loop & Process button menu choices ------ #
while True:
event, values = window.read()
if event in (None, 'Exit'):
return
print('Event = ', event)
break
print(event, values)
# ------ Process menu choices ------ #
if event == 'About...':
window.disappear()
sg.popup('About this program', 'Version 1.0',
'PySimpleGUI rocks...', grab_anywhere=True)
'PySimpleGUI Version', sg.version, grab_anywhere=True)
window.reappear()
elif event == 'Open':
filename = sg.popup_get_file('file to open', no_window=True)

View File

@ -5,13 +5,13 @@ import PySimpleGUI as sg
Demonstration of how to work with multiple colors when outputting text to a multiline element
"""
sg.change_look_and_feel('Dark Blue 3')
sg.theme('Dark Blue 3')
MLINE_KEY = '-MLINE-'+sg.WRITE_ONLY_KEY
layout = [ [sg.Text('Demonstration of Multiline Element\'s ability to show multiple colors ')],
[sg.Multiline(size=(60,20), key=MLINE_KEY)],
[sg.B('Plain'), sg.Button('Text Blue Line'), sg.Button('Text Green Line'),sg.Button('Background Blue Line'),sg.Button('Background Green Line'), sg.B('White on Green')
] ]
[sg.B('Plain'), sg.Button('Text Blue Line'), sg.Button('Text Green Line')],
[sg.Button('Background Blue Line'),sg.Button('Background Green Line'), sg.B('White on Green')] ]
window = sg.Window('Demonstration of Multicolored Multline Text', layout)

View File

@ -50,7 +50,7 @@ def the_gui():
"""
global thread_done, message, progress
sg.change_look_and_feel('Light Brown 3')
sg.theme('Light Brown 3')
layout = [[sg.Text('Long task to perform example')],
[sg.Output(size=(80, 12))],

View File

@ -43,7 +43,7 @@ def the_gui():
Reads data from a Queue and displays the data to the window
Returns when the user exits / closes the window
"""
sg.theme('Light Brown 3')
gui_queue = queue.Queue() # queue used to communicate between the gui and the threads
layout = [[sg.Text('Long task to perform example')],

View File

@ -54,7 +54,7 @@ def long_function_wrapper(work_id, gui_queue):
############################# Begin GUI code #############################
def the_gui():
sg.change_look_and_feel('Light Brown 3')
sg.theme('Light Brown 3')
# queue used to communicate between the gui and long-running code
gui_queue = queue.Queue()

View File

@ -26,7 +26,7 @@ def ShowMeTheButtons():
bcolor = ('black', 'black')
wcolor = ('white', 'black')
sg.change_look_and_feel('Black')
sg.theme('Black')
sg.set_options(auto_size_buttons=True, border_width=0,
button_color=sg.COLOR_SYSTEM_DEFAULT)

View File

@ -9,7 +9,7 @@ import time
# Free online encoder - https://www.base64-image.de/
red_x = "R0lGODlhEAAQAPeQAIsAAI0AAI4AAI8AAJIAAJUAAJQCApkAAJoAAJ4AAJkJCaAAAKYAAKcAAKcCAKcDA6cGAKgAAKsAAKsCAKwAAK0AAK8AAK4CAK8DAqUJAKULAKwLALAAALEAALIAALMAALMDALQAALUAALYAALcEALoAALsAALsCALwAAL8AALkJAL4NAL8NAKoTAKwbAbEQALMVAL0QAL0RAKsREaodHbkQELMsALg2ALk3ALs+ALE2FbgpKbA1Nbc1Nb44N8AAAMIWAMsvAMUgDMcxAKVABb9NBbVJErFYEq1iMrtoMr5kP8BKAMFLAMxKANBBANFCANJFANFEB9JKAMFcANFZANZcANpfAMJUEMZVEc5hAM5pAMluBdRsANR8AM9YOrdERMpIQs1UVMR5WNt8X8VgYMdlZcxtYtx4YNF/btp9eraNf9qXXNCCZsyLeNSLd8SSecySf82kd9qqc9uBgdyBgd+EhN6JgtSIiNuJieGHhOGLg+GKhOKamty1ste4sNO+ueenp+inp+HHrebGrefKuOPTzejWzera1O7b1vLb2/bl4vTu7fbw7ffx7vnz8f///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAJAALAAAAAAQABAAAAjUACEJHEiwYEEABniQKfNFgQCDkATQwAMokEU+PQgUFDAjjR09e/LUmUNnh8aBCcCgUeRmzBkzie6EeQBAoAAMXuA8ciRGCaJHfXzUMCAQgYooWN48anTokR8dQk4sELggBhQrU9Q8evSHiJQgLCIIfMDCSZUjhbYuQkLFCRAMAiOQGGLE0CNBcZYmaRIDLqQFGF60eTRoSxc5jwjhACFWIAgMLtgUocJFy5orL0IQRHAiQgsbRZYswbEhBIiCCH6EiJAhAwQMKU5DjHCi9gnZEHMTDAgAOw=="
sg.change_look_and_feel('Topanga')
sg.theme('Topanga')
sg.set_options(border_width=0, margins=(0, 0))
layout = [[sg.Text('Notification'+' '*14),

View File

@ -24,7 +24,7 @@ def main():
num_frames = vidFile.get(cv.CAP_PROP_FRAME_COUNT)
fps = vidFile.get(cv.CAP_PROP_FPS)
sg.change_look_and_feel('Black')
sg.theme('Black')
# ---===--- define the window layout --- #
layout = [[sg.Text('OpenCV Demo', size=(15, 1), font='Helvetica 20')],

View File

@ -1,4 +1,4 @@
import cv2, PySimpleGUI as sg
import cv2, PySimpleGUIWeb as sg
window, cap = sg.Window('Demo Application - OpenCV Integration', [[sg.Image(filename='', key='image')], ], location=(800, 400)), cv2.VideoCapture(0)
while window(timeout=20)[0] is not None:
window['image'](data=cv2.imencode('.png', cap.read()[1])[1].tobytes())

View File

@ -1,13 +1,14 @@
import cv2, PySimpleGUI as sg
window = sg.Window('Demo Application - OpenCV Integration', [[sg.Image(filename='', key='image')],], location=(800,400))
cap = cv2.VideoCapture(0) # Setup the camera as a capture device
while True: # The PSG "Event Loop"
event, values = window.read(timeout=20, timeout_key='timeout') # get events for the window with 20ms max wait
if event is None: break # if user closed window, quit
window['image'].update(data=cv2.imencode('.png', cap.read()[1])[1].tobytes()) # Update image in window
window = sg.Window('Demo Application - OpenCV Integration', [[sg.Image(filename='', key='image')], ], location=(800, 400))
cap = cv2.VideoCapture(0) # Setup the camera as a capture device
while True: # The PSG "Event Loop"
event, values = window.read(timeout=20, timeout_key='timeout') # get events for the window with 20ms max wait
if event is None: break # if user closed window, quit
window['image'].update(data=cv2.imencode('.png', cap.read()[1])[1].tobytes()) # Update image in window
"""
Putting the comment at the bottom so that you can see that the code is indeed 7 lines long. And, there is nothing
done out of the ordinary to make it 7 lines long. There are no ; for example. OK, so the if statement is on one line
but that's the only place that you would traditionally see one more line. So, call it 8 if you want.
"""
"""

View File

@ -18,7 +18,7 @@ enhance: applies local contrast enhancement on the luma channel to make the i
def main():
sg.change_look_and_feel('LightGreen')
sg.theme('LightGreen')
# define the window layout
layout = [

View File

@ -10,7 +10,7 @@ Demo program that displays a webcam using OpenCV
def main():
sg.change_look_and_feel('Black')
sg.theme('Black')
# define the window layout
layout = [[sg.Text('OpenCV Demo', size=(40, 1), justification='center', font='Helvetica 20')],

View File

@ -28,7 +28,7 @@ USING_QT = False
chars = np.asarray(list(' .,:;irsXA253hMHGS#9B&@'))
SC, GCF, WCF = .1, 1, 7/4
sg.change_look_and_feel('Black') # make it look cool
sg.theme('Black') # make it look cool
# define the window layout
# number of lines of text elements. Depends on cameras image size and the variable SC (scaller)

View File

@ -8,7 +8,7 @@ import cv2
in PySimpleGUIQt (yet).
"""
sg.change_look_and_feel('Black')
sg.theme('Black')
# define the window layout
layout = [[sg.Image(filename='', key='-IMAGE-', tooltip='Right click for exit menu')],]

View File

@ -37,7 +37,7 @@ import fitz
import PySimpleGUI as sg
from sys import exit
sg.change_look_and_feel('GreenTan')
sg.theme('GreenTan')
if len(sys.argv) == 1:
fname = sg.popup_get_file(

View File

@ -1,6 +1,6 @@
import PySimpleGUI as sg
sg.change_look_and_feel('GreenTan')
sg.theme('GreenTan')
col1 = sg.Col([[sg.Text('in pane1', text_color='blue')],
[sg.Text('Pane1')],

View File

@ -59,14 +59,15 @@ def main():
login_password_hash = '6adfb183a4a2c94a2f92dab5ade762a47889a5a1' # helloworld
password = sg.popup_get_text(
'Password: (type gui for other window)', password_char='*')
if password and password == 'gui': # Remove when pasting into your program
HashGeneratorGUI() # Remove when pasting into your program
return # Remove when pasting into your program
if PasswordMatches(password, login_password_hash):
if password == 'gui': # Remove when pasting into your program
HashGeneratorGUI() # Remove when pasting into your program
return # Remove when pasting into your program
if password and PasswordMatches(password, login_password_hash):
print('Login SUCCESSFUL')
else:
print('Login FAILED!!')
if __name__ == '__main__':
sg.theme('DarkAmber')
main()

View File

@ -2,6 +2,7 @@
import PySimpleGUI as sg
from time import sleep
sg.theme('Dark Blue 3')
"""
Demonstration of simple and multiple one_line_progress_meter's as well as the Progress Meter Element

View File

@ -21,7 +21,8 @@ graph = window['-GRAPH-']
# -------------- Magic code to integrate PyGame with tkinter -------
embed = graph.TKCanvas
os.environ['SDL_WINDOWID'] = str(embed.winfo_id())
os.environ['SDL_VIDEODRIVER'] = 'windib' # change this to 'x11' to make it work on Linux
# change this to 'x11' to make it work on Linux
os.environ['SDL_VIDEODRIVER'] = 'windib'
# ----------------------------- PyGame Code -----------------------------

View File

@ -44,7 +44,7 @@ def draw_figure(canvas, figure, loc=(0, 0)):
return figure_canvas_agg
# ------------------------------- Beginning of GUI CODE -------------------------------
sg.change_look_and_feel('Light Brown 3')
sg.theme('Light Brown 3')
fig = plt.gcf() # if using Pyplot then get the figure from the plot
figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds

View File

@ -43,7 +43,7 @@ def draw_figure(canvas, figure, loc=(0, 0)):
# ------------------------------- Beginning of GUI CODE -------------------------------
sg.change_look_and_feel('Light Brown 3')
sg.theme('Light Brown 3')
fig = plt.gcf() # if using Pyplot then get the figure from the plot
figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds

View File

@ -41,7 +41,7 @@ def execute_command_nonblocking(command, *args):
def Launcher2():
sg.change_look_and_feel('GreenTan')
sg.theme('GreenTan')
filelist = glob.glob(LOCATION_OF_YOUR_SCRIPTS+'*.py')
namesonly = []

View File

@ -123,5 +123,5 @@ def runCommand(cmd, timeout=None, window=None):
return retval
sg.change_look_and_feel('Dark Blue 3')
sg.theme('Dark Blue 3')
main()

View File

@ -8,11 +8,13 @@ import PySimpleGUI as sg
be displayed in realtime in the window.
"""
sg.theme('Dark Blue 3')
def main():
layout = [ [sg.Text('Enter the command you wish to run')],
[sg.Input(key='-IN-')],
[sg.Output(size=(60,15))],
[sg.Button('Run'), sg.Button('Exit')] ]
layout = [
[sg.Output(size=(110,30), background_color='black', text_color='white')],
[sg.T('Promt> '), sg.Input(key='-IN-', do_not_clear=False)],
[sg.Button('Run', bind_return_key=True), sg.Button('Exit')] ]
window = sg.Window('Realtime Shell Command Output', layout)
@ -27,6 +29,7 @@ def main():
def runCommand(cmd, timeout=None, window=None):
nop = None
""" run shell command
@param cmd: command to execute
@param timeout: timeout for command execution
@ -39,7 +42,7 @@ def runCommand(cmd, timeout=None, window=None):
line = line.decode(errors='replace' if (sys.version_info) < (3, 5) else 'backslashreplace').rstrip()
output += line
print(line)
window.refresh() if window else None # yes, a 1-line if, so shoot me
window.refresh() if window else nop # yes, a 1-line if, so shoot me
retval = p.wait(timeout)
return (retval, output)

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python
import PySimpleGUI as sg
import sys
'''
Quickly add a GUI to your script!
@ -13,6 +13,7 @@ The 1-line-GUI shows a form that allows the user to browse to find the filename.
stores the result in the variable fname, just like the command line parsing did.
'''
fname = ''
if len(sys.argv) == 1:
layout = [
[sg.Text('Document to open')],
@ -22,6 +23,7 @@ if len(sys.argv) == 1:
window = sg.Window('My Script', layout)
event, values = window.read()
window.close()
fname = values['-FNAME-']
else:
fname = sys.argv[1]
if not fname:

View File

@ -30,7 +30,7 @@ def draw_bars(graph, items):
def main():
sg.change_look_and_feel('LightGreen')
sg.theme('LightGreen')
# Make list to sort
num_bars = DATA_SIZE[0]//(BAR_WIDTH+1)
list_to_sort = [DATA_SIZE[1]//num_bars*i for i in range(1, num_bars)]

View File

@ -6,7 +6,7 @@ import PySimpleGUI as sg
"""
sg.set_options(element_padding=(0, 0))
# sg.change_look_and_feel('Dark')
# sg.theme('Dark')
# --- Define our "Big-Button-Spinner" compound element. Has 2 buttons and an input field --- #
NewSpinner = [sg.Button('-', size=(2, 1), font='Any 12'),
sg.Input('0', size=(2, 1), font='Any 14',

View File

@ -3,6 +3,7 @@ import PySimpleGUI as sg
import csv
# Show CSV data in Table
sg.theme('Dark Red')
def table_example():
filename = sg.popup_get_file('filename to open', no_window=True, file_types=(("CSV Files","*.csv"),))
@ -31,7 +32,7 @@ def table_example():
max_col_width=25,
auto_size_columns=True,
justification='right',
alternating_row_color='lightblue',
# alternating_row_color='lightblue',
num_rows=min(len(data), 20))]]

View File

@ -3,40 +3,48 @@ import PySimpleGUI as sg
import random
import string
# Yet another example of showing CSV data in Table
"""
Basic use of the Table Element
"""
sg.theme('Dark Red')
# ------ Some functions to help generate data for the table ------
def word():
return ''.join(random.choice(string.ascii_lowercase) for i in range(10))
def number(max_val=1000):
return random.randint(0, max_val)
def make_table(num_rows, num_cols):
data = [[j for j in range(num_cols)] for i in range(num_rows)]
data[0] = [word() for _ in range(num_cols)]
data[0] = [word() for __ in range(num_cols)]
for i in range(1, num_rows):
data[i] = [word(), *[number() for i in range(num_cols - 1)]]
return data
# ------ Make the Table Data ------
data = make_table(num_rows=15, num_cols=6)
# sg.set_options(element_padding=(0,0))
headings = [data[0][x] for x in range(len(data[0]))]
headings = [str(data[0][x]) for x in range(len(data[0]))]
layout = [[sg.Table(values=data[1:][:], headings=headings, max_col_width=25, background_color='lightblue',
# ------ Window Layout ------
layout = [[sg.Table(values=data[1:][:], headings=headings, max_col_width=25,
# background_color='light blue',
auto_size_columns=True,
display_row_numbers=True,
justification='right',
num_rows=20,
alternating_row_color='blue',
key='-table-',
# alternating_row_color='lightyellow',
key='-TABLE-',
tooltip='This is a table')],
[sg.Button('Read'), sg.Button('Double'), sg.Button('Update')],
[sg.Text('Read = read which rows are selected')], [sg.Text('Double = double the amount of data in the table')]]
[sg.Button('Read'), sg.Button('Double'), sg.Button('Change Colors')],
[sg.Text('Read = read which rows are selected')],
[sg.Text('Double = double the amount of data in the table')],
[sg.Text('Change Colors = Changes the colors of rows 8 and 9')]]
window = sg.Window('Table', layout, grab_anywhere=False, resizable=True)
# ------ Create Window ------
window = sg.Window('The Table Element', layout)
# ------ Event Loop ------
while True:
event, values = window.read()
print(event, values)
@ -45,9 +53,8 @@ while True:
if event == 'Double':
for i in range(len(data)):
data.append(data[i])
window['-table-'].update(values=data)
elif event == 'Update':
window['-table-'].update(row_colors=((8, 'white',
'red'), (9, 'black')))
window['-TABLE-'].update(values=data)
elif event == 'Change Colors':
window['-TABLE-'].update(row_colors=((8, 'white', 'red'), (9, 'green')))
window.close()

View File

@ -13,14 +13,12 @@ def TableSimulation():
['Edit', ['Paste', ['Special', 'Normal', ], 'Undo'], ],
['Help', 'About...'], ]
columm_layout = [[]]
MAX_ROWS = 20
MAX_COL = 10
for i in range(MAX_ROWS):
inputs = [sg.Text(str(i), size=(4, 1), justification='right')] + [sg.Input(size=(10, 1), pad=(
1, 1), justification='right', key=(i, j)) for j in range(MAX_COL)]
columm_layout.append(inputs)
columm_layout = [[sg.Text(str(i), size=(4, 1), justification='right')] + [sg.Input(size=(10, 1), pad=(
1, 1), justification='right', key=(i, j)) for j in range(MAX_COL)] for i in range(MAX_ROWS)]
layout = [[sg.Menu(menu_def)],
[sg.Text('Table Using Combos and Input Elements', font='Any 18')],

View File

@ -7,7 +7,7 @@ import operator
the arrow keys. The tab key works automatically, but the arrow keys are done in the code below.
"""
sg.change_look_and_feel('Dark Brown 2') # No excuse for gray windows
sg.theme('Dark Brown 2') # No excuse for gray windows
# Show a "splash" type message so the user doesn't give up waiting
sg.popup_quick_message('Hang on for a moment, this will take a bit to create....', auto_close=True, non_blocking=True)
@ -63,4 +63,4 @@ while True: # Event Loop
# if clicked button to dump the table's values
if event.startswith('Show Table'):
table = [[values[(row, col)] for col in range(MAX_COLS)] for row in range(MAX_ROWS)]
sg.popup_scrolled('your_table = [ ', ',\n'.join([str(table[i]) for i in range(MAX_ROWS)]) + ' ]', title='Copy your data from here')
sg.popup_scrolled('your_table = [ ', ',\n'.join([str(table[i]) for i in range(MAX_ROWS)]) + ' ]', title='Copy your data from here', font='fixedsys', keep_on_top=True)

View File

@ -3,10 +3,12 @@ import sys
import PySimpleGUI as sg
# Usage of Tabs in PSG
#
# sg.set_options(background_color='cornsilk4',
# element_background_color='cornsilk2',
# input_elements_background_color='cornsilk2')
sg.set_options(background_color='cornsilk4',
element_background_color='cornsilk2',
input_elements_background_color='cornsilk2')
sg.theme('Light Green 5')
tab1_layout = [[sg.Text('This is inside tab 1', background_color='darkslateblue', text_color='white')],
[sg.Input(key='-in0-')]]

View File

@ -3,7 +3,7 @@ import PySimpleGUI as sg
# Yet another example of TabGroup element
sg.change_look_and_feel('GreenTan')
sg.theme('GreenTan')
tab2_layout = [[sg.Text('This is inside tab 2')],
[sg.Text('Tabs can be anywhere now!')]]

View File

@ -1,40 +1,48 @@
#!/usr/bin/env python
import PySimpleGUI as sg
# Simple example of TabGroup element and the options available to it
# Simple example of TabGroup element
sg.change_look_and_feel('Dark Brown 1')
sg.theme('Dark Red') # Please always add color to your window
# The tab 1, 2, 3 layouts - what goes inside the tab
tab1_layout = [[sg.Text('Tab 1')],
[sg.Text('Put your layout in here')],
[sg.Text('Input something'), sg.Input(size=(12,1), key='-IN0-')]]
[sg.Text('Input something'), sg.Input(size=(12,1), key='-IN-TAB1-')]]
tab2_layout = [[sg.Text('Tab 2')]]
tab3_layout = [[sg.Text('Tab 3')]]
tab4_layout = [[sg.Text('Tab 3')]]
tab_group_layout = [[sg.Tab('Tab 1', tab1_layout, key='-TAB1-'),
# The TabgGroup layout - it must contain only Tabs
tab_group_layout = [[sg.Tab('Tab 1', tab1_layout, font='Courier 15', key='-TAB1-'),
sg.Tab('Tab 2', tab2_layout, visible=False, key='-TAB2-'),
sg.Tab('Tab 3', tab3_layout, key='-TAB3-')]]
sg.Tab('Tab 3', tab3_layout, key='-TAB3-'),
sg.Tab('Tab 4', tab3_layout, visible=False, key='-TAB4-'),
]]
# The window layout - defines the entire window
layout = [[sg.TabGroup(tab_group_layout,
selected_title_color='blue',
selected_background_color='red',
tab_background_color='green',
# selected_title_color='blue',
# selected_background_color='red',
# tab_background_color='green',
enable_events=True,
# font='Courier 18',
key='-TABGROUP-')],
[sg.Text('Make tab number'), sg.Input(key='-IN-', size=(3,1)), sg.Button('Invisible'), sg.Button('Visible')]]
window = sg.Window('My window with tabs', layout)
window = sg.Window('My window with tabs', layout, no_titlebar=False)
tab_keys = ('-TAB1-','-TAB2-','-TAB3-')
tab_keys = ('-TAB1-','-TAB2-','-TAB3-', '-TAB4-') # map from an input value to a key
while True:
event, values = window.read() # type: str, dict
event, values = window.read() # type: str, dict
print(event, values)
if event is None:
break
# handle button clicks
if event == 'Invisible':
window[tab_keys[int(values['-IN-'])-1]].update(visible=False)
if event == 'Visible':
window[tab_keys[int(values['-IN-'])-1]].update(visible=True)
window.close()

View File

@ -0,0 +1,27 @@
import PySimpleGUI as sg
"""
Allows you to "browse" through the theme settings. Click on one and you'll see a
Popup window using the color scheme you chose. It's a simply little program that demonstrates
how snappy a GUI can feel if you enable an element's events rather than waiting on a button click.
In this program, as soon as a listbox entry is clicked, the read returns.
"""
sg.theme('Dark Green 5')
layout = [[sg.Text('Look and Feel Browser')],
[sg.Text('Click a look and feel color to see demo window')],
[sg.Listbox(values=sg.theme_list(),
size=(20, 20), key='-LIST-', enable_events=True)],
[sg.Button('Exit')]]
window = sg.Window('Look and Feel Browser', layout)
while True: # Event Loop
event, values = window.read()
if event in (None, 'Exit'):
break
sg.theme(values['-LIST-'][0])
sg.popup_get_text('This is {}'.format(values['-LIST-'][0]), default_text=values['-LIST-'][0])
window.close()

View File

@ -0,0 +1,42 @@
import PySimpleGUI as sg
# import PySimpleGUIWeb as sg
# import PySimpleGUIQt as sg
"""
If you're using the PySimpleGUI color themes, then your code will a line that looks something like this:
sg.theme('Light Green 1') or sg.theme('LightGreen1')
This demo shows how to access the list of all themes to build your own previewer
"""
# Use the built-in Theme Viewer to show all of the themes and their names
# sg.theme_previewer()
# The remainder of the program duplicates the built-in Theme Viewer, allowing you to create your
# own custom theme viewer window. You can configure the number of frames per row for example. Or maybe you only
# want to see the dark themes
window_background = 'black'
def sample_layout():
return [[sg.Text('Text element'), sg.InputText('Input data here', size=(15, 1))],
[sg.Button('Ok'), sg.Button('Cancel'), sg.Slider((1, 10), orientation='h', size=(10, 15))]]
layout = [[sg.Text('List of Dark Themes Provided by PySimpleGUI', font='Default 18', background_color=window_background)]]
FRAMES_PER_ROW = 9
names = sg.theme_list()
names = [name for name in names if 'dark' in name.lower()]
row = []
for count, theme in enumerate(names):
sg.theme(theme)
if not count % FRAMES_PER_ROW:
layout += [row]
row = []
row += [sg.Frame(theme, sample_layout())]
if row:
layout += [row]
window = sg.Window('Custom Preview of Themes', layout, background_color=window_background)
window.read()
window.close()

View File

@ -4,7 +4,7 @@ import time
# Basic timer in PSG
def Timer():
sg.change_look_and_feel('Dark')
sg.theme('Dark')
sg.set_options(element_padding=(0, 0))
form_rows = [[sg.Text(size=(8, 2), font=('Helvetica', 20),
justification='center', key='text')],

View File

@ -9,7 +9,7 @@ from random import randint as randint
They're good for a quick status display / dashboard, for use on buttons (arrows), or as "simple clipart" to name a few uses
"""
sg.change_look_and_feel('Light Brown 4')
sg.theme('Light Brown 4')
SQUARE = ''
CIRCLE = ''
@ -31,7 +31,7 @@ layout = [ [sg.Text('Unicode Characters Demo', font='Def 16')],
[sg.T('Enter a Char'), sg.In(size=(2,1), key='-CHAR-', font='Any 18'), sg.T('Unicode number: '), sg.T(size=(6,1), key='-OUT NUM-')]])],
[sg.Frame('Display Unicode Characters In Range',
[[sg.T('Starting Number'), sg.In(size=(6, 1), key='-START-'), sg.T('Ending Number char: '), sg.I(size=(6, 1), key='-END-')],
[sg.B('Display Chars'), sg.T('Display Font Size'), sg.Spin(list(range(10,25)), initial_value=18, font='Any 14', key='-FONTSIZE-')],
[sg.B('Display Chars', bind_return_key=True), sg.T('Display Font Size'), sg.Spin(list(range(10,25)), initial_value=18, font='Any 14', key='-FONTSIZE-')],
])],
[sg.Multiline(size=(30,10), font='Any 18',key='-MLINE-'+sg.WRITE_ONLY_KEY)],
[sg.B(UP), sg.B(DOWN), sg.B(LEFT), sg.B(RIGHT), sg.B('Exit')] ]
@ -63,7 +63,7 @@ while True:
elif event.startswith('Display'): # process the dump range section
try:
for c in range(int(values['-START-']), int(values['-END-'])):
window['-MLINE-'+sg.WRITE_ONLY_KEY](chr(c), append=True)
window['-MLINE-'+sg.WRITE_ONLY_KEY](chr(c), append=True, text_color_for_value='red')
window.refresh()
sg.popup_animated(sg.DEFAULT_BASE64_LOADING_GIF, 'Writing chars to display', text_color='red', font='Any 20', time_between_frames=100)
except: pass

File diff suppressed because one or more lines are too long

View File

@ -13,7 +13,7 @@ youtube_executable = 'path/to/youtube-dl'
def DownloadSubtitlesGUI():
sg.change_look_and_feel('Dark')
sg.theme('Dark')
combobox = sg.Combo(values=['', ], size=(10, 1), key='lang')
layout = [

View File

@ -46,7 +46,7 @@ def show_list_by_name(window):
def main():
# ---------------- Create Form ----------------
# sg.change_look_and_feel('Topanga')
# sg.theme('Topanga')
layout = [[sg.Text('Process Killer - Choose one or more processes',
size=(45,1), font=('Helvetica', 15), text_color='red')],

BIN
DemoPrograms/db.sqlite3 Normal file

Binary file not shown.

View File

@ -1,6 +1,5 @@
# PySimpleGUI Demo Programs
## One Stop Shopping For Templates and Techniques
This folder of over 170 programs is your jump-start, spring board, boost, shove in the back, cheat sheet to get you to a solution as quickly as possible. You can think of them as Recipes from a large PySimpleGUI Cookbook.