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
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()
participants (2)
-
Cam -
jepler@unpythonic.net