PySimpleGUI / PySimpleGUI/PySimpleGUI
Question Error when running Demo_Menus.py
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 13.8k
- Forks
- 1.8k
- PR merge metrics
- No merged PRs in 30d
Description
Type of Issues (Enhancement, Error, Bug, Question)
Operating System
Mac
Python version
3.8
PySimpleGUI Port and Version
PySimpleGUI 4.26
Your Experience Levels In Months or Years
1 year Python programming experience
_________ Programming experience overall
_________ Have used another Python GUI Framework (tkinter, Qt, etc) previously (yes/no is fine)?
Description of Problem / Question / Details
Hi, I made an error while running the Demo_Menus.py and the menu at the top cannot be displayed. The running result is as follows:
Paste your code here
#!/usr/bin/env python
import PySimpleGUI as sg
"""
Demonstration of MENUS!
How do menus work? Like buttons is how.
Check out the variable menu_def for a hint on how to
define menus
"""
def second_window():
layout = [[sg.Text('The second form is small \nHere to show that opening a window using a window works')],
[sg.OK()]]
window = sg.Window('Second Form', layout)
event, values = window.read()
window.close()
def test_menus():
sg.theme('LightGreen')
sg.set_options(element_padding=(0, 0))
# ------ Menu Definition ------ #
menu_def = [['&File', ['&Open Ctrl-O', '&Save Ctrl-S', '&Properties', 'E&xit']],
['&Edit', ['&Paste', ['Special', 'Normal', ], 'Undo'], ],
['&Toolbar', ['---', 'Command &1', 'Command &2',
'---', 'Command &3', 'Command &4']],
['&Help', '&About...'], ]
right_click_menu = ['Unused', ['Right', '!&Click', '&Menu', 'E&xit', 'Properties']]
# ------ GUI Defintion ------ #
layout = [
[sg.Menu(menu_def, tearoff=False, pad=(200, 1))],
[sg.Text('Right click me for a right click menu example')],
[sg.Output(size=(60, 20))],
[sg.ButtonMenu('ButtonMenu', right_click_menu, key='-BMENU-'), sg.Button('Plain Button')],
]
window = sg.Window("Windows-like program",
layout,
default_element_size=(12, 1),
default_button_element_size=(12, 1),
right_click_menu=right_click_menu)
# ------ Loop & Process button menu choices ------ #
while True:
event, values = window.read()
if event in (sg.WIN_CLOSED, 'Exit'):
break
print(event, values)
# ------ Process menu choices ------ #
if event == 'About...':
window.disappear()
sg.popup('About this program', 'Version 1.0',
'PySimpleGUI Version', sg.version, grab_anywhere=True)
window.reappear()
elif event == 'Open':
filename = sg.popup_get_file('file to open', no_window=True)
print(filename)
elif event == 'Properties':
second_window()
window.close()
test_menus()
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported behavior on macOS with Python 3.8 using Demo_Menus.py, entering through test_menus() and its sg.Menu definition. Inspect the menu creation and capture the actual runtime error or display behavior, since the issue does not include the screenshot or error text. Done means the demo's top menu is displayed and usable without changing its intended menu entries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100