This is my code:
#!/usr/bin/perl use warnings; use Tk; use Tk::widgets; my $main = new MainWindow; $main->title('Tk_Test.pl'); $frame = $main->Frame(); $menubar = $main->Frame(-borderwidth=>2); $text = $frame->Text(-wrap=>"word", -height=>10, -font=>'Arial'); $filebutton = $menubar->Menubutton(-text=>"File"); $filemenu = $filebutton->Menu(-tearoff=>0); $filebutton->configure(-menu=>$filemenu); $filemenu->command(-command => \&print_frame, -label => "Print frame") +; $filemenu->command(-command => \&get_file, -label => "Get file"); $filemenu->command(-command => \&dir_dialog, -label => "Get dir"); # position the widgets $filebutton->pack(-side => 'left'); $menubar->pack(-side => 'top', -fill => 'x'); $frame->pack(-side => 'top', -fill => 'both'); $text->pack(-side => 'right', -fill => 'both'); $text->insert('1.0', "Write something here... Then click File/Print fr +ame\n"); MainLoop; sub print_frame { print $text->get("1.0", "end"); # prints frame text to STDOUT } sub get_file { $input_file = $main->getOpenFile(); $text->insert('1.0', "You opened $input_file\n"); print "You opened $input_file\n" if $input_file; } sub dir_dialog { my $w = shift; my $ent = shift; my $dir; $dir = $w->chooseDirectory; if (defined $dir and $dir ne '') { $ent->delete(0, 'end'); $ent->insert(0, $dir); $ent->xview('end'); } }
My problem is with sub dir_dialog. I got it from the widgets demo Common dialogs, Directory selection dialog. In the demo it works perfectly but I don't know how to connect it to my script. I'll appreciate some enlightenment.
In reply to Need to browse directories by keithvb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |