()
| 24 | |
| 25 | |
| 26 | def test_menus(): |
| 27 | |
| 28 | sg.theme('LightGreen') |
| 29 | sg.set_options(element_padding=(0, 0)) |
| 30 | |
| 31 | # ------ Menu Definition ------ # |
| 32 | menu_def = [ |
| 33 | ['&File', ['&Open Ctrl-O', '&Save Ctrl-S', '&Properties', 'E&xit']], |
| 34 | ['&Edit', ['&Paste', ['Special', 'Normal', ], 'Undo', 'Options::this_is_a_menu_key'], ], |
| 35 | ['&Toolbar', ['---', 'Command &1', 'Command &2', |
| 36 | '---', 'Command &3', 'Command &4']], |
| 37 | ['&Help', ['&About...']] |
| 38 | ] |
| 39 | |
| 40 | right_click_menu = ['Unused', ['Right', '!&Click', '&Menu', 'E&xit', 'Properties']] |
| 41 | |
| 42 | # ------ GUI Defintion ------ # |
| 43 | layout = [ |
| 44 | [sg.Menu(menu_def, tearoff=True, font='_ 12', key='-MENUBAR-')], |
| 45 | [sg.Text('Right click me for a right click menu example')], |
| 46 | [sg.Output(size=(60, 20))], |
| 47 | [sg.ButtonMenu('ButtonMenu', right_click_menu, key='-BMENU-', text_color='red', disabled_text_color='green'), sg.Button('Plain Button')], |
| 48 | ] |
| 49 | |
| 50 | window = sg.Window("Windows-like program", |
| 51 | layout, |
| 52 | default_element_size=(12, 1), |
| 53 | default_button_element_size=(12, 1), |
| 54 | right_click_menu=right_click_menu) |
| 55 | |
| 56 | # ------ Loop & Process button menu choices ------ # |
| 57 | while True: |
| 58 | event, values = window.read() |
| 59 | if event in (sg.WIN_CLOSED, 'Exit'): |
| 60 | break |
| 61 | print(event, values) |
| 62 | # ------ Process menu choices ------ # |
| 63 | if event == 'About...': |
| 64 | window.disappear() |
| 65 | sg.popup('About this program', 'Version 1.0', 'PySimpleGUI Version', sg.get_versions()) |
| 66 | window.reappear() |
| 67 | elif event == 'Open': |
| 68 | filename = sg.popup_get_file('file to open', no_window=True) |
| 69 | print(filename) |
| 70 | elif event == 'Properties': |
| 71 | second_window() |
| 72 | |
| 73 | window.close() |
| 74 | |
| 75 | |
| 76 | test_menus() |
no test coverage detected