MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / main

Function main

DemoPrograms/Demo_Menubar_Custom.py:37–79  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35"""
36
37def main():
38 sg.theme('dark green 7')
39 # sg.theme('dark gray 13')
40 sg.theme('dark red')
41 # sg.theme('black')
42
43 menu_def = [['&File', ['&Open Ctrl-O', '&Save Ctrl-S', '&Properties', 'E&xit']],
44 ['&Edit', ['Edit Me', 'Special', 'Normal',['Normal1', 'Normal2'] , 'Undo']],
45 ['!Disabled', ['Special', 'Normal',['Normal1', 'Normal2'], 'Undo']],
46 ['&Toolbar', ['---', 'Command &1::Command_Key', 'Command &2', '---', 'Command &3', 'Command &4']],
47 ['&Help', ['&About...']], ]
48
49 layout = [[sg.MenubarCustom(menu_def, pad=(0,0), k='-CUST MENUBAR-')],
50 [sg.Multiline(size=(70, 20), reroute_cprint=True, write_only=True, no_scrollbar=True, k='-MLINE-')]]
51
52 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)
53
54 # ------ Event Loop ------ #
55 while True:
56 event, values = window.read()
57 # convert ButtonMenu event so they look like Menu events
58
59 if event in (sg.WIN_CLOSED, 'Exit'):
60 break
61
62 sg.cprint(f'event = {event}', c=(sg.theme_background_color(), sg.theme_text_color()))
63 sg.cprint(f'values = {values}',c=(sg.theme_input_text_color(), sg.theme_input_background_color()))
64
65 # ------ Process menu choices ------ #
66 if event == 'About...':
67 window.disappear()
68 sg.popup('About this program', 'Simulated Menubar to accompany a simulated Titlebar',
69 'PySimpleGUI Version', sg.get_versions(), grab_anywhere=True, keep_on_top=True)
70 window.reappear()
71 elif event == 'Edit Me':
72 sg.execute_editor(__file__)
73 elif event == 'Version':
74 sg.popup_scrolled(__file__, sg.get_versions(), keep_on_top=True, non_blocking=True)
75 elif event.startswith('Open'):
76 filename = sg.popup_get_file('file to open', no_window=True)
77 print(filename)
78
79 window.close()
80
81
82if __name__ == '__main__':

Callers 1

Calls 4

readMethod · 0.95
disappearMethod · 0.95
reappearMethod · 0.95
closeMethod · 0.95

Tested by

no test coverage detected