Keep It Simple, Stupid | |
PerlMonks |
Re^4: Tk how-to?by rcseege (Pilgrim) |
on Dec 04, 2005 at 17:38 UTC ( [id://513974]=note: print w/replies, xml ) | Need Help?? |
This is good stuff, and you raise a really good point: the bind method for Canvas is overridden to be used for Canvas items. This is a pretty nasty and non-intuitive behavior, IMO. It would have been better if there had been itemBind method or something similar, but anyway... It used to be that in order to get the original implementation of bind, one had to use $canvas->Tk::bind(...), which I continue to use. As you say, CanvasBind is provided (It is basically an alias for Tk::bind), and is barely documented in the docs I have. Configure can be used as you suggest, but I'd suggest that Expose be used instead. I consider Configure to be the "big gun" in Tk when I need to react to lots of different changes in one event handler, but tend to avoid it when I can, since it gets called a lot. In this case, I think Expose will suffice -- fewer things trigger it. A quick snippet: Rob Update: I'll back off from my statement on Configure vs Expose a bit, and instead recommend that you test with both, and use one or the other. Depending on what you're doing, Configure may be the way to go. There are times when an Expose event will be called but a Configure will not. While running the above snippet, move another window in front of the Tk window, then move it away. Expose will be triggered, where Configure will not, so there's one case at least. The point is that both get called upon resize - once the rest of your app is coded, you might do some basic testing to determine which binding is triggered more often for events other than resize. You could find that the difference is negligible. An interesting note is that although ResizeRequest is listed in the Tk bind docs, it isn't supported within Tk. It's support was removed in Tk 4, because it's usefulness was questionable and it ended up causing confusion. It was triggered before the resize had happened and not after (like Configure or Expose).
In Section
Seekers of Perl Wisdom
|
|