Menus

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Menus

Cam-4
It's easy enough, using Menubutton and Menu, to make a menu pop up in
response to the user clicking a button. I want to make a menu pop up
when the user right-clicks on a canvas. This seems like a kind of common
thing to want to do but nothing in Tkinter or PMW is popping off the
page at me as a way to do this.

Am I just being really dense or is there no simple way to accomplish this?

Thanks

Cam Farnell
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Menus

Bugzilla from jepler@unpythonic.net
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()

_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss

attachment0 (196 bytes) Download Attachment