rookie_monk has asked for the wisdom of the Perl Monks concerning the following question:

Perl gurus, Thanks in advance for your knowledge! I'm sure this is fairly simple, but I do not have the slightest idea how to get the output from the button click event. What I am trying to do is have the user choose a DIR, the button event will return the path of the directory. I will then assign the path to a variable and populate a listbox. See the code below, let me know if you would prefer the whole code:
my $but = $mw -> Button(-text=>"Find Directory", -command =>\&get_path) -> pack(); # This is what I used, but it is wrong # my($first) = $but; # &LoadListBox($first); sub get_path { my $filepath = $mw->chooseDirectory() or return(); $ent -> delete(0, 'end'); $ent -> insert(0,"$filepath"); return($filepath); } sub LoadListBox($) { my $test = @_; #$lb->delete('0.1', 'end'); # Just use a plain old grep readdir pipeline to create a list of # filenames for our listbox. opendir (DIR, $test) || die("Cannot open directory"); $lb->insert('end', grep { -f $_ && -r $_ } readdir DIR); close DIR; }

Replies are listed 'Best First'.
Re: How do you retrieve output from Button widget?
by Anonymous Monk on Aug 25, 2010 at 20:22 UTC
    You got that turned around, you need this
    $mw -> Button(-text=>"Find Directory", -command =>\&LoadListBox) -> pack(); ... sub LoadListBox { ### CHOOSE DIRECTORY, and if successfull, read filelist my $filepath = $mw->chooseDirectory() or return(); .... }
      Awesome!!! Thanks... Yea that works much better :)