Fixed menu definition (Help should have had a list like the other entries). Added key to the menu, etc. It's been a long time since updated.
This commit is contained in:
parent
70085de109
commit
5accdda30f
|
@ -1,10 +1,13 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Demonstration of MENUS!
|
Demo of Menu element, ButtonMenu element and right-click menus
|
||||||
How do menus work? Like buttons is how.
|
|
||||||
Check out the variable menu_def for a hint on how to
|
The same basic structure is used for all menus in PySimpleGUI.
|
||||||
define menus
|
Each entry is a list of items to display. If any of those items is a list, then a cancade menu is added.
|
||||||
|
|
||||||
|
Copyright 2018, 2019, 2020, 2021, 2022 PySimpleGUI
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,20 +27,22 @@ def test_menus():
|
||||||
sg.set_options(element_padding=(0, 0))
|
sg.set_options(element_padding=(0, 0))
|
||||||
|
|
||||||
# ------ Menu Definition ------ #
|
# ------ Menu Definition ------ #
|
||||||
menu_def = [['&File', ['&Open Ctrl-O', '&Save Ctrl-S', '&Properties', 'E&xit']],
|
menu_def = [
|
||||||
['&Edit', ['&Paste', ['Special', 'Normal', ], 'Undo'], ],
|
['&File', ['&Open Ctrl-O', '&Save Ctrl-S', '&Properties', 'E&xit']],
|
||||||
|
['&Edit', ['&Paste', ['Special', 'Normal', ], 'Undo', 'Options::this_is_a_menu_key'], ],
|
||||||
['&Toolbar', ['---', 'Command &1', 'Command &2',
|
['&Toolbar', ['---', 'Command &1', 'Command &2',
|
||||||
'---', 'Command &3', 'Command &4']],
|
'---', 'Command &3', 'Command &4']],
|
||||||
['&Help', '&About...'], ]
|
['&Help', ['&About...']]
|
||||||
|
]
|
||||||
|
|
||||||
right_click_menu = ['Unused', ['Right', '!&Click', '&Menu', 'E&xit', 'Properties']]
|
right_click_menu = ['Unused', ['Right', '!&Click', '&Menu', 'E&xit', 'Properties']]
|
||||||
|
|
||||||
# ------ GUI Defintion ------ #
|
# ------ GUI Defintion ------ #
|
||||||
layout = [
|
layout = [
|
||||||
[sg.Menu(menu_def, tearoff=False, pad=(200, 1))],
|
[sg.Menu(menu_def, tearoff=True, font='_ 12', key='-MENUBAR-')],
|
||||||
[sg.Text('Right click me for a right click menu example')],
|
[sg.Text('Right click me for a right click menu example')],
|
||||||
[sg.Output(size=(60, 20))],
|
[sg.Output(size=(60, 20))],
|
||||||
[sg.ButtonMenu('ButtonMenu', right_click_menu, key='-BMENU-'), sg.Button('Plain Button')],
|
[sg.ButtonMenu('ButtonMenu', right_click_menu, key='-BMENU-', text_color='red', disabled_text_color='green'), sg.Button('Plain Button')],
|
||||||
]
|
]
|
||||||
|
|
||||||
window = sg.Window("Windows-like program",
|
window = sg.Window("Windows-like program",
|
||||||
|
@ -55,8 +60,7 @@ def test_menus():
|
||||||
# ------ Process menu choices ------ #
|
# ------ Process menu choices ------ #
|
||||||
if event == 'About...':
|
if event == 'About...':
|
||||||
window.disappear()
|
window.disappear()
|
||||||
sg.popup('About this program', 'Version 1.0',
|
sg.popup('About this program', 'Version 1.0', 'PySimpleGUI Version', sg.get_versions())
|
||||||
'PySimpleGUI Version', sg.version, grab_anywhere=True)
|
|
||||||
window.reappear()
|
window.reappear()
|
||||||
elif event == 'Open':
|
elif event == 'Open':
|
||||||
filename = sg.popup_get_file('file to open', no_window=True)
|
filename = sg.popup_get_file('file to open', no_window=True)
|
||||||
|
|
Loading…
Reference in New Issue