From: Josef Wolf Date: 2006-09-05T02:06:35+09:00 Subject: Re: How to properly bind context menus to canvas in Ruby/Tk? On Mon, Sep 04, 2006 at 12:45:34AM +0900, Paul Lutus wrote: Thanks for your reply, Paul! > > Unfortunately, this don't work as desired. As soon as the binding to the > > object is done, the canvas binding seems to be overridden. Even when > > right-klicking on empty space in the canvas, the object's menu is invoked. > > > > Any ideas what I am doing wrong here? > > First, rename the second menu something other than "menu" You have already > used that name, and this multiple use is causing you a lot of confusion. I admit that this is bad style :-) I've made copy/paste. In the real program, the creation/binding of the menus is done in different methods, thus they are actually two different variables (beacuse they are local to their method) > Second, after a bit of experimentation, I offer this educated guess. The > rectangle object cannot process mouse events, so it cannot invoke a context > menu different from that bound to the canvas. AFAIK, the rectangle is no real object in its own right. The canvas handles everything for it. That's the reason why its binding is done with canvas.itembind() instead of rect.bind(). IMHO, it is very important to understand this difference. > It is apparent that the canvas is receiving all mouse events, not the > rectangle, Exactly > and in order for the rectangle to launch its own context menu, > it would have to process mouse events independently. AFAICS it can't. The canvas handles those events. But for some reason the canvas fails to differentiate. > I want to emphasize this is just a guess, and I don't use the 'Tk' library > because it is too poorly documented. It's poorly documented, but it works great once you figure out how to use it :-( Especially the canvas widget is pure black magic. The concept of attaching arbitrary tags to items combined to the ability to attach bindings to the tags is very powerfull. > Have you considered using something other than 'Tk'? I'm not aware of any usable alternatives. What would you suggest?