I'm working on a Tk app that uses the ListBox method in Tk to return results from a search. All well and good until it goes out of scope in the subroutine that sets it up.
What I am trying to do, without success up to this point, is to create a reference to this method so that I don't have a huge subroutine that both defines the list box and takes care of it's processing.
I've tried to set up my list box with a reference as:
# snippet of a subroutine that defines the widget layout my $res; { my $results = $search_frame->Listbox( -background => "white", -relief => "sunken", -borderwidth => 2, -width => 20, -height => 12, ) ->place( -in => $search_frame, -x => 20, -y => 175); $res = \$results; }
but I keep getting the message that $ref isn't defined when I try to access it later in the program by
$res->insert('end', $list[$_]->{last});
I'm assuming, and perhaps incorrectly, that when I move out of the sub that defines the listbox, I'm losing scope. But if I have to move the $ref outside as a global, doesn't that sort of defeat the purpose of defining it as a reference to the ListBox method?
I've been banging my head for a few days on this now, so any help would be greatly appreciated!
In reply to Calling a TK Method by reference by Popcorn Dave
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |