[Tutor] events and popup menus
Prasad, Ramit
ramit.prasad at jpmorgan.com
Tue May 1 23:29:42 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
> try:
> self.popup.tk_popup(event.x_root, event.y_root, 0)
>
> finally:
> # make sure to release the grab (Tk 8.0a1 only)
> self.popup.grab_release()
>
I would probably use a lambda to pass the picture name (where LARGE_VIEW is a module level unique string identifier).
self.popup.add_command(label=LARGE_VIEW, command=lambda event: self.selectPicture( LARGE_VIEW) )
Or if you need the event in selectPicture
self.popup.add_command(label=LARGE_VIEW, command=lambda event: self.selectPicture( LARGE_VIEW, event) )
Ramit
Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423
--
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
More information about the Tutor
mailing list