How to find out path of widget in TK-like style ?

Joel HATSCH <[email protected]> Thu, 19 Jul 2007 22:42:25 +0200
Newsgroups gmane.comp.lang.perl.tk
Message-ID <[email protected]>
Hello *,

I first though this is a totally newbee FAQ, but after browsing the web and asking several experienced colleagues, it looks like it's not so dumb...

OK, so here it goes : I did a lot of Tk programming in the past. There, when you want to access a widget, you address it using it's hierarchical name like .frame1.frame2.mybutton. In ptk however, you use variables to store the objects. If you know the parent's variable, you can browse through its children to find the given widget. However, there doesn't seem to be a function that maps the string ".frame1.frame2.mybutton" to the corresponding widget's variable. This would be a very useful thing when writing generic procedures, or accessing widgets from different sections of the code : given $frame, you could access $frame.mybutton, regardless of what $frame is actually pointing to.

So far, people I asked told me they use global variables to store all the widgets they create. Works basically fine, but is not very nice if you use hundreds of widgets in your application ! Other suggestion was a kind of mapping table (hash) that would allow, having the path string, to return the variable representing the widgets. Implemented, works perfectly, but I still keep asking myself : 

shouldn't there be built-in functions for this ? or am I doing something methodologically completely wrong ?

Anyone ?

TIA

Joel
--++**==--++**==--++**==--++**==--++**==--++**==--++**==
ptk mailing list
[email protected]
https://mailman.stanford.edu/mailman/listinfo/ptk