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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.