Popup menu won't hide on Linux
dhein at acm.org
Sat Sep 21 01:49:36 CEST 2002
dhein at acm.org (Coot) wrote in message news:<a3a96207.0209151220.5228a262 at posting.google.com>...
> When a popup menu is displayed, I expect that it should goes away when
> one of the menu items is clicked (button <1>) or when I click anywhere
> else (such that the focus is no longer on the popup menu).
> However, on Linux, the latter behavior doesn't happen. The popup
> remains on top of the main app window and the only way to get rid of
> it is to click one of its menu command items or close the application.
> This behavior isn't there on Windows.
> Can anyone tell me how to solve, or work around, the problem???
> Here is some example code you can use to demonstrate this problem for
> yourself (taken from
> # menu-example-4.py
> from Tkinter import *
> root = Tk()
> def hello():
> print "hello!"
> # create a popup menu
> menu = Menu(root, tearoff=0)
> menu.add_command(label="Undo", command=hello)
> menu.add_command(label="Redo", command=hello)
> # create a canvas
> frame = Frame(root, width=512, height=512)
> def popup(event):
> menu.post(event.x_root, event.y_root)
> # attach popup to canvas
> frame.bind("<Button-3>", popup)
OK, on Linux I have to watch for a <FocusOut> event and "unpost" when
that event fires. If I do that and click outside the window, then the
Here is the new code:
from Tkinter import *
root = Tk()
# create a canvas
frame = Frame(root, width=512, height=512)
# create a popup menu
menu = Menu(frame, tearoff=0)
# attach popup to canvas
More information about the Python-list