简体   繁体   English

带有弹出菜单的Mac OS X Python tkinter.TclError

[英]Mac OS X Python tkinter.TclError with Popup Menu

I am trying to summon a Popup menu with the tkinter python GUI toolkit on Mac OS X. This works just fine on Windows, but throws this TclError on Mac OS X. I have ActiveTcl 8.6 installed on the machine. 我正在尝试在Mac OS X上使用tkinter python GUI工具箱调用弹出菜单。这在Windows上可以正常运行,但在Mac OS X上会抛出此TclError。我在计算机上安装了ActiveTcl 8.6。 All the other GUI elements (so far) have worked just fine. 所有其他GUI元素(到目前为止)都运行良好。 Do you guys have any ideas how to fix this? 你们对解决这个问题有任何想法吗? The traceback is below. 追溯如下。

Exception in Tkinter callback
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tkinter/__init__.py", line 1487, in __call__
    return self.func(*args)
  File "gui.py", line 57, in popup
    self.menu.post(event.x_root, event.y_root)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tkinter/__init__.py", line 2778, in post
    self.tk.call(self._w, 'post', x, y)
_tkinter.TclError

Referring to this SO post , you can fix this by binding the menu to a Frame or Tk object. 参考本SO帖子 ,您可以通过将菜单绑定到Frame或Tk对象来解决此问题。 Something like: 就像是:

self.config(menu=self.menu)

if self is your root window. 如果self是您的根窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM