The menu does not seem to be working. It is not clickable and does not generate any event when I click it.
macOS Catalina 10.15.1
Python 3.8
PySimpleGUI 4.4.1
1 year Python programming experience
5 year Programming experience overall
No Have used another Python GUI Framework (tkiner, Qt, etc) previously (yes/no is fine)?
menu = Menu([['File', ['Open', 'Save', 'Exit']],
['Edit', ['Paste', ['Special', 'Normal', ], 'Undo'], ],
['Help', 'About...'], ],
key=MainWindow.MENU)
layout = [[menu],
[left_column, right_column]
]
self._window = Window('Ortho',
layout,
size=(1280, 720),
return_keyboard_events=True)
while True:
event, value = window.Read()
print(event)
do_stuff()
Thank you for your help and for your awesome library !
Can you try running the menu demo from the demo programs folder on GitHub? (Demo_Menus.py)
I tried it, it is not working either.
Have you been running PySimpleGUI prior to using 3.8? Do you have 3.6 or 3.7.1 installed as well perhaps?
No I have not. I have just tried the demo program with Python 3.7.4 (the only other Python 3 distribution I have on my computer) and it still does not work.
tkinter has some problems in 3.7 versions. Tables are one area in particular. To make matters worse, Macs and tkinter have struggled. If you search through the issues, you'll see notes on the incompatibilities.
See if this Trinket based Menu demo works differently for you. If so how.
https://pysimplegui.trinket.io/demo-programs#/demo-programs/menu-bar
I assume you're getting nothing printed out for example.
The Trinket version is running 4.4.1. The source code for PySimpleGUI.py is included with the demo program. I'm guessing this is likely a Mac specific problem.
The Demo program that is run when I execute
import PySimpleGUI as sg
sg.main()
runs properly except for the menu, so yes you are probably right, it is likely to be a Mac specific issue. Do you think that there is anything I could do to make it work ? At the end of the day, my application is going to be used on a Windows PC.
Do you think that there is anything I could do to make it work ? At the end of the day, my application is going to be used on a Windows PC.
The quickest and easiest way to make it work is to write it on a Windows PC or a Linux machine. That's the quickest in my opinion because as you've seen, it works.
If you don't mind losing some features and including Qt in your project, then you could move over to PySimpleGUIQt as a number of Mac users have done.
The alternative is to begin to troubleshoot the different versions of Mac components being used... the OS release, the Python / tkinter version, etc. If you're really good at Macs, then maybe you'll be able to look through the Issues here that describe combinations of Mac components that work when put together.
Looking at Stack Overflow questions, Macs and tkinter have been a problem stretching back many years. Some problems reported years ago are a problem today. It's not possible to set the button colors correctly using tkinter on a Mac. I don't know why. I've spent many days trying to get around it and I've not been successful.
The situation isn't looking good for the Mac to be honest. The number of problems greatly outweighs the number of installs compared to other operating systems.
It may soon come to the point that PySimpleGUI will not support tkinter on the Mac.
I have tried to use PySimpleGUIQt, it does not work with Python 3.8 (shiboken2 is not supported), it works with 3.7.4 but the UI seems less stable, and the Menu is still not working.
I think I will move on now, it is not a big deal.
Anyway, thank you very much for your help and for your time !
The menu bar is not clickable using PySimpleGUIQt too? It's really sounding like an unusual Mac situation that may be local to your machine.
The menu bar itself and the interactions are done at a lower level than PySimpleGUI or the application. You can be hung in a loop inside your application and have the menus or other constructs still be interactive. The events they generate many not go anywhere, but the animations and clicking of the text should be independent.
If you have a moment, it would be helpful to understand what you found less stable...
works with 3.7.4 but the UI seems less stable
What in particular is less stable? Are you talking about the Mac stuff, tkinter, Qt, PySimpleGUI or something entirely differently? There are so many pieces that work together that it's confusing when there's a summary like this without understanding the details of the underlying data.
The menu bar is not clickable using PySimpleGUIQt too?
Indeed the menu bar is not clickable even with PySimpleGUIQt. I tested it using the demo program.
import PySimpleGuyQt as sg
sg.main()
If you have a moment, it would be helpful to understand what you found less stable...
In fact, it works as good as PySimpleGui. There is nothing to complain about. I think that I was a bit frustrated regarding the menu bar when I wrote the message, sorry about that.
Thank you very much !
No doubt it's been frustrating for you! I'm sorry to hear there's been no success despite 2 frameworks, to get menus operational.
Closing since this appears to be only in 1 system and it's happening across multiple frameworks
I'm having the same issue, and it seems to be a problem with the window focus.
Pressing "Cmd + Tab" twice fixes the issue for me.
Additionally, if you don't want to make it so that you have to use the "Cmd + Tab" fix above, placing this right after a window is finalized worked for me. Since finder is nearly always enabled on Mac, it just jumps back and forth between Finder to Python which seems to enable the Menu.
Note* Mac will ask permission if it is ok to run the process the very first time from wherever you are calling the code (command line, IDE, ...) but it won't after that for the same location.
import subprocess
from platform import system as platform
import PySimpleGUI as sg
# ...
# Finalize main window here #
# ...
if platform() == 'Darwin':
subprocess.call(["/usr/bin/osascript", "-e", 'tell app "Finder" to set frontmost of process "Finder" to true'])
subprocess.call(["/usr/bin/osascript", "-e", 'tell app "Finder" to set frontmost of process "python" to true'])
This is derived from the tip here
Most helpful comment
I'm having the same issue, and it seems to be a problem with the window focus.
Pressing "Cmd + Tab" twice fixes the issue for me.