Added ability to change theme using the example Combo element
This commit is contained in:
parent
eb63e97549
commit
7bd8a02e80
|
@ -17,10 +17,13 @@ import PySimpleGUI as sg
|
||||||
|
|
||||||
NAME_SIZE=23
|
NAME_SIZE=23
|
||||||
|
|
||||||
|
def make_window(theme=None):
|
||||||
def name(name):
|
def name(name):
|
||||||
dots = NAME_SIZE-len(name)-2
|
dots = NAME_SIZE-len(name)-2
|
||||||
return sg.Text(name + ' ' + '•'*dots, size=(NAME_SIZE,1), justification='r',pad=(0,0), font='Courier 10')
|
return sg.Text(name + ' ' + '•'*dots, size=(NAME_SIZE,1), justification='r',pad=(0,0), font='Courier 10')
|
||||||
|
|
||||||
|
sg.theme(theme)
|
||||||
|
|
||||||
treedata = sg.TreeData()
|
treedata = sg.TreeData()
|
||||||
|
|
||||||
treedata.Insert("", '_A_', 'Tree Item 1', [1234], )
|
treedata.Insert("", '_A_', 'Tree Item 1', [1234], )
|
||||||
|
@ -33,7 +36,7 @@ layout_l = [[sg.Menu([['File', ['Exit']], ['Edit', ['Edit Me', ]]])],
|
||||||
[name('Input'), sg.Input(s=15)],
|
[name('Input'), sg.Input(s=15)],
|
||||||
[name('Multiline'), sg.Multiline(s=(15,2))],
|
[name('Multiline'), sg.Multiline(s=(15,2))],
|
||||||
[name('Output'), sg.Output(s=(15,2))],
|
[name('Output'), sg.Output(s=(15,2))],
|
||||||
[name('Combo'), sg.Combo(['Combo',], s=(15,2))],
|
[name('Combo'), sg.Combo(sg.theme_list(), default_value=sg.theme(), s=(15,22), enable_events=True, k='-COMBO-')],
|
||||||
[name('OptionMenu'), sg.OptionMenu(['OptionMenu',],s=(15,2))],
|
[name('OptionMenu'), sg.OptionMenu(['OptionMenu',],s=(15,2))],
|
||||||
[name('Checkbox'), sg.Checkbox('Checkbox')],
|
[name('Checkbox'), sg.Checkbox('Checkbox')],
|
||||||
[name('Radio'), sg.Radio('Radio', 1)],
|
[name('Radio'), sg.Radio('Radio', 1)],
|
||||||
|
@ -61,18 +64,30 @@ layout_r = [[name('Canvas'), sg.Canvas(background_color=sg.theme_button_color()
|
||||||
[name('StatusBar'), sg.StatusBar('StatusBar')],
|
[name('StatusBar'), sg.StatusBar('StatusBar')],
|
||||||
[name('Sizegrip'), sg.Sizegrip()] ]
|
[name('Sizegrip'), sg.Sizegrip()] ]
|
||||||
|
|
||||||
layout = [[sg.Col(layout_l), sg.Col(layout_r)]]
|
layout = [[sg.T('PySimpleGUI Elements - Use Combo to Change Themes', font='_ 18', justification='c', expand_x=True)],
|
||||||
|
[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 = sg.Window('The PySimpleGUI Element List', layout, finalize=True, right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_EXIT)
|
||||||
|
|
||||||
window['-PBAR-'].update(30)
|
window['-PBAR-'].update(30)
|
||||||
window['-GRAPH-'].draw_image(data=sg.EMOJI_BASE64_HAPPY_JOY, location=(0,50))
|
window['-GRAPH-'].draw_image(data=sg.EMOJI_BASE64_HAPPY_JOY, location=(0,50))
|
||||||
|
|
||||||
|
return window
|
||||||
|
|
||||||
|
def main():
|
||||||
|
window = make_window()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
event, values = window.read()
|
event, values = window.read()
|
||||||
if event == sg.WIN_CLOSED or event == 'Exit':
|
if event == sg.WIN_CLOSED or event == 'Exit':
|
||||||
break
|
break
|
||||||
if event == 'Edit Me':
|
if event == 'Edit Me':
|
||||||
sg.execute_editor(__file__)
|
sg.execute_editor(__file__)
|
||||||
|
if values['-COMBO-'] != sg.theme():
|
||||||
|
sg.theme(values['-COMBO-'])
|
||||||
|
window.close()
|
||||||
|
window = make_window()
|
||||||
window.close()
|
window.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
Reference in New Issue