Got a few of the Demos up to date with changes standard to many demos (edit me, get versions for example)
This commit is contained in:
parent
dba12e59f2
commit
f1f60b03a1
|
@ -11,7 +11,7 @@
|
||||||
Displays the values dictionary entry for each element
|
Displays the values dictionary entry for each element
|
||||||
And more!
|
And more!
|
||||||
|
|
||||||
Copyright 2021 PySimpleGUI
|
Copyright 2021, 2022 PySimpleGUI
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
|
@ -36,7 +36,7 @@ def make_window(theme):
|
||||||
sg.Image(data=sg.DEFAULT_BASE64_LOADING_GIF, enable_events=True, key='-GIF-IMAGE-'),],
|
sg.Image(data=sg.DEFAULT_BASE64_LOADING_GIF, enable_events=True, key='-GIF-IMAGE-'),],
|
||||||
[sg.Checkbox('Checkbox', default=True, k='-CB-')],
|
[sg.Checkbox('Checkbox', default=True, k='-CB-')],
|
||||||
[sg.Radio('Radio1', "RadioDemo", default=True, size=(10,1), k='-R1-'), sg.Radio('Radio2', "RadioDemo", default=True, size=(10,1), k='-R2-')],
|
[sg.Radio('Radio1', "RadioDemo", default=True, size=(10,1), k='-R1-'), sg.Radio('Radio2', "RadioDemo", default=True, size=(10,1), k='-R2-')],
|
||||||
[sg.Combo(values=('Combo 1', 'Combo 2', 'Combo 3'), default_value='Combo 1', readonly=True, k='-COMBO-'),
|
[sg.Combo(values=('Combo 1', 'Combo 2', 'Combo 3'), default_value='Combo 1', readonly=False, k='-COMBO-'),
|
||||||
sg.OptionMenu(values=('Option 1', 'Option 2', 'Option 3'), k='-OPTION MENU-'),],
|
sg.OptionMenu(values=('Option 1', 'Option 2', 'Option 3'), k='-OPTION MENU-'),],
|
||||||
[sg.Spin([i for i in range(1,11)], initial_value=10, k='-SPIN-'), sg.Text('Spin')],
|
[sg.Spin([i for i in range(1,11)], initial_value=10, k='-SPIN-'), sg.Text('Spin')],
|
||||||
[sg.Multiline('Demo of a Multi-Line Text Element!\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\nYou get the point.', size=(45,5), expand_x=True, expand_y=True, k='-MLINE-')],
|
[sg.Multiline('Demo of a Multi-Line Text Element!\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\nYou get the point.', size=(45,5), expand_x=True, expand_y=True, k='-MLINE-')],
|
||||||
|
@ -88,9 +88,7 @@ def make_window(theme):
|
||||||
|
|
||||||
]]
|
]]
|
||||||
layout[-1].append(sg.Sizegrip())
|
layout[-1].append(sg.Sizegrip())
|
||||||
window = sg.Window('All Elements Demo', layout, right_click_menu=right_click_menu_def, right_click_menu_tearoff=True, grab_anywhere=True, resizable=True, margins=(0,0), use_custom_titlebar=True, finalize=True, keep_on_top=True,
|
window = sg.Window('All Elements Demo', layout, right_click_menu=right_click_menu_def, right_click_menu_tearoff=True, grab_anywhere=True, resizable=True, margins=(0,0), use_custom_titlebar=True, finalize=True, keep_on_top=True)
|
||||||
# scaling=2.0,
|
|
||||||
)
|
|
||||||
window.set_min_size(window.size)
|
window.set_min_size(window.size)
|
||||||
return window
|
return window
|
||||||
|
|
||||||
|
@ -151,7 +149,7 @@ def main():
|
||||||
elif event == 'Edit Me':
|
elif event == 'Edit Me':
|
||||||
sg.execute_editor(__file__)
|
sg.execute_editor(__file__)
|
||||||
elif event == 'Versions':
|
elif event == 'Versions':
|
||||||
sg.popup(sg.get_versions(), keep_on_top=True)
|
sg.popup_scrolled(__file__, sg.get_versions(), keep_on_top=True, non_blocking=True)
|
||||||
|
|
||||||
window.close()
|
window.close()
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
|
@ -88,8 +88,7 @@ while True:
|
||||||
# sg.Print(event, values)
|
# sg.Print(event, values)
|
||||||
if event == sg.WIN_CLOSED or event == 'Exit':
|
if event == sg.WIN_CLOSED or event == 'Exit':
|
||||||
break
|
break
|
||||||
if event == 'Edit Me':
|
|
||||||
sg.execute_editor(__file__)
|
|
||||||
if values['-COMBO-'] != sg.theme():
|
if values['-COMBO-'] != sg.theme():
|
||||||
sg.theme(values['-COMBO-'])
|
sg.theme(values['-COMBO-'])
|
||||||
window.close()
|
window.close()
|
||||||
|
@ -99,8 +98,10 @@ while True:
|
||||||
sg.set_options(use_custom_titlebar=use_custom_titlebar)
|
sg.set_options(use_custom_titlebar=use_custom_titlebar)
|
||||||
window.close()
|
window.close()
|
||||||
window = make_window()
|
window = make_window()
|
||||||
|
if event == 'Edit Me':
|
||||||
|
sg.execute_editor(__file__)
|
||||||
elif event == 'Version':
|
elif event == 'Version':
|
||||||
sg.popup_scrolled(sg.get_versions(), __file__, keep_on_top=True, non_blocking=True)
|
sg.popup_scrolled(__file__, sg.get_versions(), keep_on_top=True, non_blocking=True)
|
||||||
window.close()
|
window.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,21 @@
|
||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
import random
|
import random
|
||||||
|
|
||||||
# Bars drawing in PySimpleGUI
|
"""
|
||||||
#
|
Demo - Using a Graph Element to make Bar Charts
|
||||||
# .--.
|
|
||||||
# | |
|
The Graph Element is very versatile. Because you can define your own
|
||||||
# .--.| |.--.
|
coordinate system, it makes producing graphs of many lines (bar, line, etc) very
|
||||||
# | || || |
|
straightforward.
|
||||||
# | || || |
|
|
||||||
# | || || |
|
In this Demo a "bar" is nothing more than a rectangle drawn in a Graph Element (draw_rectangle).
|
||||||
# .--.| || || |
|
|
||||||
# .--.| || || || |.--.
|
To make things a little more interesting, this is a barchart with that data values
|
||||||
# | || || || || || |
|
placed as labels atop each bar, another Graph element method (draw_text)
|
||||||
# | || || || || || |
|
|
||||||
# .--.| || || || || || |.--.
|
Copyright 2022 PySimpleGUI
|
||||||
# | || || || || || || || |.--.
|
"""
|
||||||
# | || || || || || || || || |
|
|
||||||
# '--''--''--''--''--''--''--''--''--'
|
|
||||||
|
|
||||||
|
|
||||||
BAR_WIDTH = 50 # width of each bar
|
BAR_WIDTH = 50 # width of each bar
|
||||||
|
@ -38,12 +37,13 @@ while True:
|
||||||
|
|
||||||
graph.erase()
|
graph.erase()
|
||||||
for i in range(7):
|
for i in range(7):
|
||||||
graph_value = random.randint(0, GRAPH_SIZE[1])
|
graph_value = random.randint(0, GRAPH_SIZE[1]-25) # choose an int just short of the max value to give room for the label
|
||||||
graph.draw_rectangle(top_left=(i * BAR_SPACING + EDGE_OFFSET, graph_value),
|
graph.draw_rectangle(top_left=(i * BAR_SPACING + EDGE_OFFSET, graph_value),
|
||||||
bottom_right=(i * BAR_SPACING + EDGE_OFFSET + BAR_WIDTH, 0),
|
bottom_right=(i * BAR_SPACING + EDGE_OFFSET + BAR_WIDTH, 0),
|
||||||
fill_color=sg.theme_button_color()[1])
|
fill_color='green')
|
||||||
|
# fill_color=sg.theme_button_color()[1])
|
||||||
|
|
||||||
graph.draw_text(text=graph_value, location=(i*BAR_SPACING+EDGE_OFFSET+25, graph_value+10))
|
graph.draw_text(text=graph_value, location=(i*BAR_SPACING+EDGE_OFFSET+25, graph_value+10), font='_ 14')
|
||||||
|
|
||||||
# Normally at the top of the loop, but because we're drawing the graph first, making it at the bottom
|
# Normally at the top of the loop, but because we're drawing the graph first, making it at the bottom
|
||||||
event, values = window.read()
|
event, values = window.read()
|
||||||
|
|
|
@ -39,7 +39,7 @@ def main():
|
||||||
# sg.theme('black')
|
# sg.theme('black')
|
||||||
|
|
||||||
menu_def = [['&File', ['&Open Ctrl-O', '&Save Ctrl-S', '&Properties', 'E&xit']],
|
menu_def = [['&File', ['&Open Ctrl-O', '&Save Ctrl-S', '&Properties', 'E&xit']],
|
||||||
['&Edit', ['Me', 'Special', 'Normal',['Normal1', 'Normal2'] , 'Undo']],
|
['&Edit', ['Edit Me', 'Special', 'Normal',['Normal1', 'Normal2'] , 'Undo']],
|
||||||
['!Disabled', ['Special', 'Normal',['Normal1', 'Normal2'], 'Undo']],
|
['!Disabled', ['Special', 'Normal',['Normal1', 'Normal2'], 'Undo']],
|
||||||
['&Toolbar', ['---', 'Command &1::Command_Key', 'Command &2', '---', 'Command &3', 'Command &4']],
|
['&Toolbar', ['---', 'Command &1::Command_Key', 'Command &2', '---', 'Command &3', 'Command &4']],
|
||||||
['&Help', ['&About...']], ]
|
['&Help', ['&About...']], ]
|
||||||
|
@ -47,7 +47,7 @@ def main():
|
||||||
layout = [[sg.MenubarCustom(menu_def, pad=(0,0), k='-CUST MENUBAR-')],
|
layout = [[sg.MenubarCustom(menu_def, pad=(0,0), k='-CUST MENUBAR-')],
|
||||||
[sg.Multiline(size=(70, 20), reroute_cprint=True, write_only=True, no_scrollbar=True, k='-MLINE-')]]
|
[sg.Multiline(size=(70, 20), reroute_cprint=True, write_only=True, no_scrollbar=True, k='-MLINE-')]]
|
||||||
|
|
||||||
window = sg.Window("Custom Titlebar with Custom (Simulated) Menubar", layout, use_custom_titlebar=True, keep_on_top=True)
|
window = sg.Window("Custom Titlebar with Custom (Simulated) Menubar", layout, use_custom_titlebar=True, keep_on_top=True, right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_VER_EXIT)
|
||||||
|
|
||||||
# ------ Event Loop ------ #
|
# ------ Event Loop ------ #
|
||||||
while True:
|
while True:
|
||||||
|
@ -66,8 +66,10 @@ def main():
|
||||||
sg.popup('About this program', 'Simulated Menubar to accompany a simulated Titlebar',
|
sg.popup('About this program', 'Simulated Menubar to accompany a simulated Titlebar',
|
||||||
'PySimpleGUI Version', sg.get_versions(), grab_anywhere=True, keep_on_top=True)
|
'PySimpleGUI Version', sg.get_versions(), grab_anywhere=True, keep_on_top=True)
|
||||||
window.reappear()
|
window.reappear()
|
||||||
elif event == 'Me':
|
elif event == 'Edit Me':
|
||||||
sg.execute_editor(__file__)
|
sg.execute_editor(__file__)
|
||||||
|
elif event == 'Version':
|
||||||
|
sg.popup_scrolled(__file__, sg.get_versions(), keep_on_top=True, non_blocking=True)
|
||||||
elif event.startswith('Open'):
|
elif event.startswith('Open'):
|
||||||
filename = sg.popup_get_file('file to open', no_window=True)
|
filename = sg.popup_get_file('file to open', no_window=True)
|
||||||
print(filename)
|
print(filename)
|
||||||
|
|
|
@ -51,10 +51,8 @@ def Menubar(menu_def, text_color, background_color, pad=(0, 0)):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
sg.theme('dark green 7')
|
sg.theme('dark green 7')
|
||||||
sg.theme('dark amber')
|
|
||||||
# sg.theme('dark purple 3')
|
|
||||||
|
|
||||||
menu_def = [['&File', ['&Open Ctrl-O', '&Save Ctrl-S', '&Properties', 'E&xit']],
|
menu_def = [['&File', ['&Open & Ctrl-O', '&Save & Ctrl-S', '&Properties', 'E&xit']],
|
||||||
['&Edit', [['Special', 'Normal',['Normal1', 'Normal2'] ], 'Undo'], ],
|
['&Edit', [['Special', 'Normal',['Normal1', 'Normal2'] ], 'Undo'], ],
|
||||||
['!Disabled', [['Special', 'Normal',['Normal1', 'Normal2'] ], 'Undo'], ],
|
['!Disabled', [['Special', 'Normal',['Normal1', 'Normal2'] ], 'Undo'], ],
|
||||||
['&Toolbar', ['---', 'Command &1::Command_Key', 'Command &2', '---', 'Command &3', 'Command &4']],
|
['&Toolbar', ['---', 'Command &1::Command_Key', 'Command &2', '---', 'Command &3', 'Command &4']],
|
||||||
|
@ -78,13 +76,13 @@ def main():
|
||||||
|
|
||||||
layout3 = [[sg.Multiline(size=(70, 20), reroute_stdout=True, reroute_cprint=True, write_only=True)],]
|
layout3 = [[sg.Multiline(size=(70, 20), reroute_stdout=True, reroute_cprint=True, write_only=True)],]
|
||||||
|
|
||||||
window = sg.Window("Custom Titlebar and Menu", layout, use_custom_titlebar=True, finalize=True)
|
window = sg.Window("Custom Titlebar and Menu", layout, use_custom_titlebar=True, finalize=True, right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_VER_EXIT)
|
||||||
|
|
||||||
win_loc = window.current_location()
|
win_loc = window.current_location()
|
||||||
|
|
||||||
window2 = sg.Window("Traditional Titlebar and Menu", layout2, finalize=True, location=(win_loc[0]-window.size[0]-40, win_loc[1]))
|
window2 = sg.Window("Traditional Titlebar and Menu", layout2, finalize=True, location=(win_loc[0]-window.size[0]-40, win_loc[1]), right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_VER_EXIT)
|
||||||
|
|
||||||
window3 = sg.Window("Output Window", layout3, finalize=True, location=(win_loc[0]-window.size[0]//1.5, win_loc[1]+window.size[1]+30), use_custom_titlebar=True)
|
window3 = sg.Window("Output Window", layout3, finalize=True, location=(int(win_loc[0]-window.size[0]//1.5), int(win_loc[1]+window.size[1]+30)), use_custom_titlebar=True, right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_VER_EXIT)
|
||||||
|
|
||||||
|
|
||||||
# ------ Event Loop ------ #
|
# ------ Event Loop ------ #
|
||||||
|
@ -97,7 +95,11 @@ def main():
|
||||||
|
|
||||||
if event in (sg.WIN_CLOSED, 'Exit'):
|
if event in (sg.WIN_CLOSED, 'Exit'):
|
||||||
break
|
break
|
||||||
|
elif event == 'Edit Me':
|
||||||
|
sg.execute_editor(__file__)
|
||||||
|
elif event == 'Version':
|
||||||
|
sg.popup_scrolled(__file__, sg.get_versions(), keep_on_top=True, non_blocking=True)
|
||||||
|
|
||||||
sg.cprint(f'event = {event}', c='white on red')
|
sg.cprint(f'event = {event}', c='white on red')
|
||||||
sg.cprint(f'values = {values}', c='white on green')
|
sg.cprint(f'values = {values}', c='white on green')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue