bdalzell has asked for the wisdom of the Perl Monks concerning the following question:
I want to start a listbox as a subroutine and return the choice to the main program which is otherwise a command line program (don't laugh please).
How do I return the picked value to the main program.
The code below shows the value in the command line window when clicked on but does not display the output of:print "From top level: selection is $choice\n";
in the command line window when the listbox is closed.
#!/usr/bin/perl use strict; use Tk; my @listbox_items = qw/frodo bilbo rabbits orcs smaug gandolf/; my $choice = &myListBox(@listbox_items); print "From top level: selection is $choice\n"; sub myListBox{ my @listbox_items = @_; my $mw = new MainWindow; $mw->geometry('400x300'); my $lb = $mw->Listbox(-selectmode => "single")->pack( ); $lb->insert('end', @listbox_items); $lb->bind('<Button-1>'); $mw->Button( -text => "Close Window", -command => sub { $mw->withdraw(); return $choice;})->pack; ##double click on item from listbox $lb -> bind('<Double-1>'=> sub { $choice = $_[0]->get($_[0]->curselection), print "in loop selection is $choice\n"; }, ); MainLoop; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perl tk listbox how to return choice to main program
by kcott (Archbishop) on Jun 27, 2013 at 04:49 UTC | |
|
Re: perl tk listbox how to return choice to main program
by Anonymous Monk on Jun 27, 2013 at 00:11 UTC | |
by bdalzell (Sexton) on Jul 01, 2013 at 16:21 UTC |