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; }
In reply to perl tk listbox how to return choice to main program by bdalzell
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |