Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Event binding for right mouse click 1

Status
Not open for further replies.

neerg

Technical User
Jun 1, 2003
4
US
Hi,

I need to invoke a frame within my simulation window to enable me to select or perform task.

Just like a right mouse click on your normal desktop enviroment. A frame will appear with undo, cut, copy ...

How do I do this in my unix system
 
I think you need that:
Code:
menu .m -tearoff 0
.m add command -label cut   -command mycut
.m add command -label copy  -command mycopy
.m add command -label paste -command mypaste
bind . <3> { mypopup %x %y }
proc mypopup {x y} { 
  incr x [winfo rootx .]
  incr y [winfo rooty .]
  tk_popup .m $x $y
}
proc mycut   {} { tk_messageBox -message mycut }
proc mycopy  {} { tk_messageBox -message mycopy }
proc mypaste {} { tk_messageBox -message mypaste }

Here the menu is a child of the root window (.).
The right button of the mouse is numbered 3 hence the 'bind . <3> ...'
A popup menu is poped up with tk_popup.
Can can try 'tearoff 1' to see what appens to the menu.

Good luck!

ulis
 
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 &quot;<Alt-9>&quot; instead of &quot;<Alt-KeyPress-9>&quot;. They then wondered why their application didn't respond to their &quot;<Alt-5>&quot; binding. It was because that was interpreted by the application as &quot;<Alt-ButtonPress-5>&quot; instead of &quot;<Alt-KeyPress-5>&quot;.

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top