Great example,
ulis. Just a couple of changes you might want to make.
One is in regards to positioning the popup menu. As you've gathered,
tk_popup requires X/Y coordinates relative to the upper-left corner of the screen. However, the event detail substitutions for
%x and
%y give you the mouse position relative to the upper-left corner of the widget that receives the event. You solve this with your
mypopup procedure. But a much easier way is to use the
%X and
%Y (note the capitalization) event detail substitutions, which directly give you screen-relative coordinates.
The other suggestion I have is a minor stylistic preference of mine. I prefer not to use abbreviated event descriptions (like <3>) in my bindings, because they aren't as descriptive and can cause confusion for people who have to maintain my code later. For example, there was a thread a couple of months ago where a person was using KeyPress event abbreviations like "<Alt-9>" instead of "<Alt-KeyPress-9>". They then wondered why their application didn't respond to their "<Alt-5>" binding. It was because that was interpreted by the application as "<Alt-ButtonPress-5>" instead of "<Alt-KeyPress-5>".
So, in your code sample, you could eliminate your
mypopup procedure and instead do:
Code:
bind . <ButtonPress-3> { tk_popup .m %X %Y }
- Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax