[Tutor] events and popup menus

Chris Hare chare at labr.net
Tue May 1 22:59:52 CEST 2012

I have four images in a frame.  I want to pop up a menu when the user right clicks on an image, and when they choose an option from the menu, execute the action.  

I can create the popup menu, and bind it to the image.  However, what I can't figure out is how to detect in the popup menu code which image fired the event so I can do the right thing (like display a larger version of the image, etc.)

# create a menu
self.popup = Menu(self.pictureWindow, tearoff=0)
 self.popup.add_command(label="Change Picture", command=self.selectPicture)
 self.popup.add_command(label="Make Primary", command=self.selectPicture)
 self.popup.add_command(label="Large View", command=self.selectPicture)

self.picture1.bind("<Button-1>", self.do_popup)

 def do_popup(self,event):
            # display the popup menu
           self.popup.tk_popup(event.x_root, event.y_root, 0)

                         # make sure to release the grab (Tk 8.0a1 only)

Thanks for the advice!


More information about the Tutor mailing list