[Tkinter-discuss] Menus

jepler@unpythonic.net jepler at unpythonic.net
Thu Sep 15 04:18:03 CEST 2005


I think you're looking for the tk_popup() method.  

    def tk_popup(self, x, y, entry=""):
        """Post the menu at position X,Y with entry ENTRY."""
        self.tk.call('tk_popup', self._w, x, y, entry)

Here's an example of its use:
from Tkinter import *

t = Tk()
t.option_add("*Menu.tearOff", "0")
m = Menu(t) 
m.insert_command(END, label="A ...")
m.insert_command(END, label="B ...")
m.insert_command(END, label="C ...")
m.insert_command(END, label="D ...")

c = Canvas(t)
c.bind("<ButtonPress-3><ButtonRelease-3>",
	lambda e: m.tk_popup(e.x_root, e.y_root))
c.pack()

t.mainloop()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050914/7eaef3fc/attachment.pgp


More information about the Tkinter-discuss mailing list