For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > October 2004 > Re: Locating widgets









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Locating widgets
Michael van Nieuwenhuize

2004-10-01, 3:56 pm

Rich,

One way that I have done it in the past is use the Advertise method to tag
a sub-widget with a name.
When I want to retrieve this widget I then use subwidget("advertised_name")
to get a ref to it. You can
find this in Master Perl Tk chapter 14. These are methods mainly used for
mega-widget creation but
works like this as well.

#allow mainWindow to advertise your widget.

$mw->Advertise("tag_name" => $myWidget_ref);

#get back the ref to your widget..

$myWidget = $mw->Subwidget("tag_name");

So basically you can give all the widgets you want to retrieve there own
tag names and recall
them at will by using the Subwidget and tag you are interested in.

Check M/PTK pages 327-328 for more details..

Mike


At 09:39 AM 10/1/2004, Rich Duzenbury wrote:
>Hi,
>
>I'm curious as to how I might easily locate a widget.
>
>I might create entry fields thusly:
>
># Create a Tk::Entry object
>sub an_entry {
> my ($parent, $text, $width) = @_;
> $text = lc($text);
> $text =~ s/\s+/_/g;
> $parent->Entry(
> -textvariable => \$entries{$text},
> -width => $width,
> -background => 'white',
> );
>}
>
>And most of the time, all I care about is the hash that holds the
>%entries. I can read and write data there, and I know that Tk keeps the
>controls up-to-date with the contents of the hash.
>
>However, I sometimes want to access the control associated with a
>particular -textvariable, to (for example) set the focus on that
>control.
>
>Is there a Tk way to do that, or do I have to set up and maintain a data
>structure to map the names to their respective objects?
>
>--
>Regards,
>Rich
>
>
>
>-++**==--++**==--++**==--++**==--++**==--++**==--++**==
>This message was posted through the Stanford campus mailing list
>server. If you wish to unsubscribe from this mailing list, send the
>message body of "unsubscribe ptk" to majordomo@lists.stanford.edu


-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server. If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to majordomo@lists.stanford.edu
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com