Hi, when you post code, you can enclose the words code and /code in angle<> brackets. This helps with the formatting!
Update: Oh, I see,usleep(2500000); this is a problem!, you don't want to sleep! If you do that, the stuff that runs the GUI is not gonna be running. Once you start the GUI, it waits for some event to happen. original post continues, may still be of value to you...
Here is a snippet from one of my programs. The text variable is where the stuff goes that is typed in (there is a search command that the user types in here). Then I bind the RETURN key to an anon sub that just calls another routine. I haven't used this waitVariable thing and I'm not sure what it would different than this. Our functional requirement sounds similar so...here's some code..
$f_dialog->Label (-text => 'Search Query')->pack(-side=>'left');
my $e_search =$f_dialog->Entry (-textvariable => \$tv_search_command,)
+->pack(-side=>'left');
$e_search->bind("<Return>", sub {enter_pressed();} );
......
sub enter_pressed()
{
#first few lines of this sub...
$text->delete("1.0", 'end'); #Update 000ops this is for another wind
+ow
#not needed for entry window
#I think text visible to user entry gets
#cleared by the time we are here.
#I do think making a copy of entered text for
#further processing is good idea though...
my $search_command = $tv_search_command;
....blah
}
I think you can just give the address of "enter_pressed()" rather they way this was done. This anon sub may have done more than just call one routine in the past, its been a few years since I've looked at this code. Of course you may not need a separate sub and can do it all in the anon sub. Adapt as you need.
If you want a button instead of using Return, then you don't need the bind. Just associate a routine with a click button. |