79 lines
3.3 KiB
Python
79 lines
3.3 KiB
Python
|
import PySimpleGUI as sg
|
||
|
|
||
|
"""
|
||
|
Demo - Element List
|
||
|
|
||
|
All elements (almost) shown in 1 window as simply as possible.
|
||
|
Two of the elements can't be demonstrated
|
||
|
Titlebar
|
||
|
MenubarCustom
|
||
|
|
||
|
This is because the Normal titlebar and the Menu element are shown.
|
||
|
|
||
|
Copyright 2022 PySimpleGUI
|
||
|
"""
|
||
|
|
||
|
# sg.theme('Dark Grey 13') # uncommment to see how a particular theme looks
|
||
|
|
||
|
NAME_SIZE=23
|
||
|
|
||
|
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')
|
||
|
|
||
|
treedata = sg.TreeData()
|
||
|
|
||
|
treedata.Insert("", '_A_', 'Tree Item 1', [1234], )
|
||
|
treedata.Insert("", '_B_', 'B', [])
|
||
|
treedata.Insert("_A_", '_A1_', 'Sub Item 1', ['can', 'be', 'anything'], )
|
||
|
treedata.Insert("", '_C_', 'C', [], )
|
||
|
|
||
|
layout_l = [[sg.Menu([['File', ['Exit']], ['Edit', ['Edit Me', ]]])],
|
||
|
[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))],
|
||
|
[name('Combo'), sg.Combo(['Combo',], s=(15,2))],
|
||
|
[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))],
|
||
|
[name('Listbox'), sg.Listbox(['Listbox', 'Listbox 2'], s=(15,2))],
|
||
|
[name('Image'), sg.Image(sg.EMOJI_BASE64_HAPPY_THUMBS_UP)],
|
||
|
[name('Graph'), sg.Graph((125, 50), (0,0), (125,50), k='-GRAPH-')] ]
|
||
|
|
||
|
layout_r = [[name('Canvas'), sg.Canvas(background_color=sg.theme_button_color()[1], size=(125,50))],
|
||
|
[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()] ]
|
||
|
|
||
|
layout = [[sg.Col(layout_l), sg.Col(layout_r)]]
|
||
|
window = sg.Window('The PySimpleGUI Element List', layout, finalize=True, right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_EXIT)
|
||
|
|
||
|
window['-PBAR-'].update(30)
|
||
|
window['-GRAPH-'].draw_image(data=sg.EMOJI_BASE64_HAPPY_JOY, location=(0,50))
|
||
|
|
||
|
while True:
|
||
|
event, values = window.read()
|
||
|
if event == sg.WIN_CLOSED or event == 'Exit':
|
||
|
break
|
||
|
if event == 'Edit Me':
|
||
|
sg.execute_editor(__file__)
|
||
|
window.close()
|
||
|
|
||
|
|