MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / main

Function main

DemoPrograms/Demo_Menubar_Custom_and_Traditional.py:54–118  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

52 return sg.Column([row], background_color=background_color, pad=(0,0), expand_x=True)
53
54def main():
55 sg.theme('dark green 7')
56
57 menu_def = [['&File', ['&Open & Ctrl-O', '&Save & Ctrl-S', '&Properties', 'E&xit']],
58 ['&Edit', [['Special', 'Normal',['Normal1', 'Normal2'] ], 'Undo'], ],
59 ['!Disabled', [['Special', 'Normal',['Normal1', 'Normal2'] ], 'Undo'], ],
60 ['&Toolbar', ['---', 'Command &1::Command_Key', 'Command &2', '---', 'Command &3', 'Command &4']],
61 ['&Help', ['&About...']], ]
62
63 layout = [[Menubar(menu_def, sg.theme_button_color()[1], sg.theme_button_color()[0], (5, 0))],
64 [sg.Text('This is the "Simulated" Titlebar and Menubar Window')],
65 [sg.Checkbox('Checkbox 1', k='-C1W1-'), sg.Checkbox('Checkbox 2', k='-C2W1-')],
66 [sg.Slider((0,100), orientation='h', size=(20,20), k='-S1-')],
67 [sg.HorizontalSeparator()],
68 [sg.Radio('Radio 1', 1, k='-R1W1-'), sg.Radio('Radio 2', 1, k='-R2W1-')],
69 [sg.Ok(k='OK 1'), sg.Cancel(k='Cancel 1')],]
70
71 layout2 = [[sg.Menu(menu_def, tearoff=False, key='-MENU BAR-')], # This is how a Menu is normally defined
72 [sg.Text('This is the "Traditional" Titlebar and Menubar Window')],
73 [sg.Checkbox('Checkbox 1', k='-C1W2-'), sg.Checkbox('Checkbox 2', k='-C2W2-')],
74 [sg.Slider((0,100), orientation='h', size=(20,20), k='-S2-')],
75 [sg.HorizontalSeparator()],
76 [sg.Radio('Radio 1', 1, k='-R1W2-'), sg.Radio('Radio 2', 1, k='-R2W2-')],
77 [sg.Ok(k='OK 2'), sg.Cancel(k='Cancel 2')],]
78
79 layout3 = [[sg.Multiline(size=(70, 20), reroute_stdout=True, reroute_cprint=True, write_only=True)],]
80
81 window = sg.Window("Custom Titlebar and Menu", layout, use_custom_titlebar=True, finalize=True, right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_VER_EXIT)
82
83 win_loc = window.current_location()
84
85 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)
86
87 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)
88
89
90 # ------ Event Loop ------ #
91 while True:
92 window, event, values = sg.read_all_windows()
93 # convert ButtonMenu event so they look like Menu events
94 elem = window.find_element(event, silent_on_error=True)
95 if elem and elem.Type == sg.ELEM_TYPE_BUTTONMENU:
96 event = values[event]
97
98 if event in (sg.WIN_CLOSED, 'Exit'):
99 break
100 elif event == 'Edit Me':
101 sg.execute_editor(__file__)
102 elif event == 'Version':
103 sg.popup_scrolled(__file__, sg.get_versions(), keep_on_top=True, non_blocking=True)
104
105 sg.cprint(f'event = {event}', c='white on red')
106 sg.cprint(f'values = {values}', c='white on green')
107
108 # ------ Process menu choices ------ #
109 if event == 'About...':
110 window.disappear()
111 sg.popup('About this program', 'Simulated Menubar to accompany a simulated Titlebar',

Calls 6

current_locationMethod · 0.95
find_elementMethod · 0.95
disappearMethod · 0.95
reappearMethod · 0.95
closeMethod · 0.95
MenubarFunction · 0.85

Tested by

no test coverage detected