Python Forum

Full Version: macOS Catalina and Python menu issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am experiencing a Python menu issue on both of my Mac's. One Mac has macOS Catalina and Python 3.7.4 via pyEnv with Tcl/Tk 8.6.9 and the other has macOS Catalina and Python 3.8.0. via pyEnv and Tcl/Tk 8.6.9 and both area exhibiting the same behavior. This behavior did not exist before upgrading from macOS Mojave to macOS Catalina.

When I enter the following code in the terminal I get a small tk window that appears.

>$ python
>>> import tkinter as tk
>>> root = tk.Tk()

The menu at the top of the screen changes to a Python menu with the Apple logo and 'python File Edit Window Help' which does not respond to mouse clicks. I have to take focus from the python window either by CMD+tabbing out of the window (or click out) back to terminal or the desktop and then CMD+tab (or click) back to the python window to give it focus and then the menu at the top responds to mouse clicks.

If you are running Catalina and you execute the above code, do you get the same behavior, or does your menu respond to mouse clicks before taking focus from python?

I don't know how to figure out if this is macOS issue (most likely), Python issue, or a Tcl/Tk issue.
add: root.mainloop()
and see if it behaves differently
Since tkinter starts a new window instance, it's probably better to run from .py file
(Oct-23-2019, 10:23 AM)Larz60+ Wrote: [ -> ]add: root.mainloop()
and see if it behaves differently
Since tkinter starts a new window instance, it's probably better to run from .py file

Sorry, I should have added that even with the root.mainloop() in a .py file and run from the Visual Studio Code (my IDE) it still behaves the same.

A thread over at stackoverflow tried adding in update_idletasks() and that didn't work either, thinking it was a focus issue.
the interactive prompt is great for running snippets of code, figuring out problems. With
tkinter it's only good for the basic app a box. All menus need to coded nothing preset, I don't have a mac but I guess it's a default by the operating system. Put your code in a file and run it. Check out elfbot tk menu it's assumes you know how import and you'll need to change the print command it's set up for python 2.7 - I modified the first example
from tkinter import Tk, Menu

root = Tk()

def hello():
    print( "hello!")

# create a toplevel menu
menubar = Menu(root)
menubar.add_command(label="Hello!", command=hello)
menubar.add_command(label="Quit!", command= root.destroy)

# display the menu
root.config(menu=menubar)
root.mainloop()
the link you gave is another problem they created a filedialog in the init and froze the gui. I would recommend guizero to start, it's a tkinter wrapper that is easy to create apps, then tkinter, pyqt5, wx or any other.
you can find it here
best of luck
(Oct-25-2019, 04:02 AM)joe_momma Wrote: [ -> ]the interactive prompt is great for running snippets of code, figuring out problems. With tkinter it's only good for the basic app a box. All menus need to coded nothing preset, I don't have a mac but I guess it's a default by the operating system. Put your code in a file and run it. Check out elfbot tk menu it's assumes you know how import and you'll need to change the print command it's set up for python 2.7 - I modified the first example
 from tkinter import Tk, Menu root = Tk() def hello(): print( "hello!") # create a toplevel menu menubar = Menu(root) menubar.add_command(label="Hello!", command=hello) menubar.add_command(label="Quit!", command= root.destroy) # display the menu root.config(menu=menubar) root.mainloop() 
the link you gave is another problem they created a filedialog in the init and froze the gui. I would recommend guizero to start, it's a tkinter wrapper that is easy to create apps, then tkinter, pyqt5, wx or any other. you can find it here best of luck

I just pasted this into my IDE and ran it. The 'python' menu cannot be clicked until I change focus to another window and then come back to the tkinter window.
hey save my example as a .py file open up your terminal and enter python yourfile.py,
report back
(Oct-26-2019, 03:58 PM)joe_momma Wrote: [ -> ]hey save my example as a .py file open up your terminal and enter python yourfile.py, report back
The behavior is the same.
I don't have a solution, but the issue described here sounds identical to an upstream Tk issue on macOS Catalina, which I reported a few months ago, but is still unresolved due to difficulty reproducing the issue or finding a working solution for it.

Please see the upstream ticket and add a comment if you're interested in getting updates or possibly helping to investigate it: https://core.tcl-lang.org/tk/tktview?name=bf93d098d7