2022-02-03 01:39:18 +00:00
import PySimpleGUI as sg
"""
Demo - Element List
2022-02-16 21:55:11 +00:00
All elements shown in 1 window as simply as possible .
2022-02-03 01:39:18 +00:00
Copyright 2022 PySimpleGUI
"""
2022-05-16 10:08:06 +00:00
use_custom_titlebar = True if sg . running_trinket ( ) else False
2022-02-03 01:39:18 +00:00
2022-02-03 13:24:36 +00:00
def make_window ( theme = None ) :
2022-02-03 14:13:16 +00:00
2022-02-16 21:55:11 +00:00
NAME_SIZE = 23
2022-04-21 16:42:56 +00:00
2022-02-03 13:24:36 +00:00
def name ( name ) :
dots = NAME_SIZE - len ( name ) - 2
return sg . Text ( name + ' ' + ' • ' * dots , size = ( NAME_SIZE , 1 ) , justification = ' r ' , pad = ( 0 , 0 ) , font = ' Courier 10 ' )
sg . theme ( theme )
2022-04-21 16:42:56 +00:00
# NOTE that we're using our own LOCAL Menu element
if use_custom_titlebar :
Menu = sg . MenubarCustom
else :
Menu = sg . Menu
2022-02-03 13:24:36 +00:00
treedata = sg . TreeData ( )
treedata . Insert ( " " , ' _A_ ' , ' Tree Item 1 ' , [ 1234 ] , )
treedata . Insert ( " " , ' _B_ ' , ' B ' , [ ] )
treedata . Insert ( " _A_ " , ' _A1_ ' , ' Sub Item 1 ' , [ ' can ' , ' be ' , ' anything ' ] , )
2022-02-04 12:53:45 +00:00
layout_l = [
2022-02-03 13:24:36 +00:00
[ name ( ' Text ' ) , sg . Text ( ' Text ' ) ] ,
[ name ( ' Input ' ) , sg . Input ( s = 15 ) ] ,
[ name ( ' Multiline ' ) , sg . Multiline ( s = ( 15 , 2 ) ) ] ,
[ name ( ' Output ' ) , sg . Output ( s = ( 15 , 2 ) ) ] ,
2022-02-16 21:55:11 +00:00
[ name ( ' Combo ' ) , sg . Combo ( sg . theme_list ( ) , default_value = sg . theme ( ) , s = ( 15 , 22 ) , enable_events = True , readonly = True , k = ' -COMBO- ' ) ] ,
2022-02-03 13:24:36 +00:00
[ name ( ' OptionMenu ' ) , sg . OptionMenu ( [ ' OptionMenu ' , ] , s = ( 15 , 2 ) ) ] ,
[ name ( ' Checkbox ' ) , sg . Checkbox ( ' Checkbox ' ) ] ,
[ name ( ' Radio ' ) , sg . Radio ( ' Radio ' , 1 ) ] ,
[ name ( ' Spin ' ) , sg . Spin ( [ ' Spin ' , ] , s = ( 15 , 2 ) ) ] ,
[ name ( ' Button ' ) , sg . Button ( ' Button ' ) ] ,
[ name ( ' ButtonMenu ' ) , sg . ButtonMenu ( ' ButtonMenu ' , sg . MENU_RIGHT_CLICK_EDITME_EXIT ) ] ,
[ name ( ' Slider ' ) , sg . Slider ( ( 0 , 10 ) , orientation = ' h ' , s = ( 10 , 15 ) ) ] ,
2022-02-03 14:13:16 +00:00
[ name ( ' Listbox ' ) , sg . Listbox ( [ ' Listbox ' , ' Listbox 2 ' ] , no_scrollbar = True , s = ( 15 , 2 ) ) ] ,
2022-02-03 13:24:36 +00:00
[ name ( ' Image ' ) , sg . Image ( sg . EMOJI_BASE64_HAPPY_THUMBS_UP ) ] ,
[ name ( ' Graph ' ) , sg . Graph ( ( 125 , 50 ) , ( 0 , 0 ) , ( 125 , 50 ) , k = ' -GRAPH- ' ) ] ]
2022-05-16 10:08:06 +00:00
layout_r = [ [ name ( ' Canvas ' ) , sg . Canvas ( background_color = sg . theme_button_color ( ) [ 1 ] , size = ( 125 , 40 ) ) ] ,
2022-02-03 13:24:36 +00:00
[ name ( ' ProgressBar ' ) , sg . ProgressBar ( 100 , orientation = ' h ' , s = ( 10 , 20 ) , k = ' -PBAR- ' ) ] ,
[ name ( ' Table ' ) , sg . Table ( [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] ] , [ ' Col 1 ' , ' Col 2 ' , ' Col 3 ' ] , num_rows = 2 ) ] ,
[ name ( ' Tree ' ) , sg . Tree ( treedata , [ ' Heading ' , ] , num_rows = 3 ) ] ,
[ name ( ' Horizontal Separator ' ) , sg . HSep ( ) ] ,
[ name ( ' Vertical Separator ' ) , sg . VSep ( ) ] ,
[ name ( ' Frame ' ) , sg . Frame ( ' Frame ' , [ [ sg . T ( s = 15 ) ] ] ) ] ,
[ name ( ' Column ' ) , sg . Column ( [ [ sg . T ( s = 15 ) ] ] ) ] ,
[ name ( ' Tab, TabGroup ' ) , sg . TabGroup ( [ [ sg . Tab ( ' Tab1 ' , [ [ sg . T ( s = ( 15 , 2 ) ) ] ] ) , sg . Tab ( ' Tab2 ' , [ [ ] ] ) ] ] ) ] ,
[ name ( ' Pane ' ) , sg . Pane ( [ sg . Col ( [ [ sg . T ( ' Pane 1 ' ) ] ] ) , sg . Col ( [ [ sg . T ( ' Pane 2 ' ) ] ] ) ] ) ] ,
[ name ( ' Push ' ) , sg . Push ( ) , sg . T ( ' Pushed over ' ) ] ,
[ name ( ' VPush ' ) , sg . VPush ( ) ] ,
[ name ( ' Sizer ' ) , sg . Sizer ( 1 , 1 ) ] ,
[ name ( ' StatusBar ' ) , sg . StatusBar ( ' StatusBar ' ) ] ,
[ name ( ' Sizegrip ' ) , sg . Sizegrip ( ) ] ]
2022-04-21 16:42:56 +00:00
# Note - LOCAL Menu element is used (see about for how that's defined)
layout = [ [ Menu ( [ [ ' File ' , [ ' Exit ' ] ] , [ ' Edit ' , [ ' Edit Me ' , ] ] ] , k = ' -CUST MENUBAR- ' , p = 0 ) ] ,
2022-05-16 10:08:06 +00:00
[ sg . T ( ' PySimpleGUI Elements - Use Combo to Change Themes ' , font = ' _ 14 ' , justification = ' c ' , expand_x = True ) ] ,
[ sg . Checkbox ( ' Use Custom Titlebar & Menubar ' , use_custom_titlebar , enable_events = True , k = ' -USE CUSTOM TITLEBAR- ' , p = 0 ) ] ,
[ sg . Col ( layout_l , p = 0 ) , sg . Col ( layout_r , p = 0 ) ] ]
2022-02-16 21:55:11 +00:00
2022-02-04 12:53:45 +00:00
window = sg . Window ( ' The PySimpleGUI Element List ' , layout , finalize = True , right_click_menu = sg . MENU_RIGHT_CLICK_EDITME_VER_EXIT , keep_on_top = True , use_custom_titlebar = use_custom_titlebar )
2022-02-16 21:55:11 +00:00
window [ ' -PBAR- ' ] . update ( 30 ) # Show 30% complete on ProgressBar
window [ ' -GRAPH- ' ] . draw_image ( data = sg . EMOJI_BASE64_HAPPY_JOY , location = ( 0 , 50 ) ) # Draw something in the Graph Element
2022-02-03 13:24:36 +00:00
return window
2022-02-16 21:55:11 +00:00
window = make_window ( )
while True :
event , values = window . read ( )
2022-05-05 11:19:20 +00:00
# sg.Print(event, values)
2022-02-16 21:55:11 +00:00
if event == sg . WIN_CLOSED or event == ' Exit ' :
break
2022-06-11 13:01:27 +00:00
2022-02-16 21:55:11 +00:00
if values [ ' -COMBO- ' ] != sg . theme ( ) :
sg . theme ( values [ ' -COMBO- ' ] )
window . close ( )
window = make_window ( )
if event == ' -USE CUSTOM TITLEBAR- ' :
use_custom_titlebar = values [ ' -USE CUSTOM TITLEBAR- ' ]
2022-05-05 11:19:20 +00:00
sg . set_options ( use_custom_titlebar = use_custom_titlebar )
2022-02-16 21:55:11 +00:00
window . close ( )
window = make_window ( )
2022-06-11 13:01:27 +00:00
if event == ' Edit Me ' :
sg . execute_editor ( __file__ )
2022-02-16 21:55:11 +00:00
elif event == ' Version ' :
2022-06-11 13:01:27 +00:00
sg . popup_scrolled ( __file__ , sg . get_versions ( ) , keep_on_top = True , non_blocking = True )
2022-02-16 21:55:11 +00:00
window . close ( )