Python Forum
[Tkinter] macOS Catalina and Python menu issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] macOS Catalina and Python menu issue
#1
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.
Reply
#2
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
Reply
#3
(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.
Reply
#4
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
Reply
#5
(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.
Reply
#6
hey save my example as a .py file open up your terminal and enter python yourfile.py,
report back
Reply
#7
(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.
Reply
#8
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  macOS Sonoma (14) seems to need a newer version of Tcl/Tk gernophil 1 1,024 Oct-11-2023, 05:53 PM
Last Post: deanhystad
  UI modules: which is most suitable for macOS app design? Anon_Brown 1 1,846 Nov-19-2021, 06:24 PM
Last Post: Larz60+
  macOS GUI pythonnewbi 5 2,996 Jul-05-2020, 03:56 PM
Last Post: ndc85430
  Nesting menu buttons tkinter for python Mocap 1 2,695 Jul-18-2019, 11:46 AM
Last Post: metulburr
  [Tkinter] Image with pillow on macos not showing rhoekstra 3 4,689 May-04-2019, 11:48 PM
Last Post: Larz60+
  Packaging VTK and ITK for macOS sandrider 0 1,996 Nov-01-2018, 05:24 AM
Last Post: sandrider
  [Tkinter] [python]Problem in creating menu[/python] yamoon 10 5,257 Aug-01-2018, 09:01 PM
Last Post: Larz60+
  About Dialog in PyQt5 on macOS cpuin 0 2,858 Jan-23-2018, 08:50 PM
Last Post: cpuin
  packaging a PyQt app for macOS danboid 0 3,087 Mar-30-2017, 06:57 PM
Last Post: danboid

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020