my $top = MainWindow -> new(title=>"Choose Directory(must be a project Directory)"); $top->withdraw; my $t = $top->Toplevel; # my $top = new MainWindow; # $top->withdraw; # my $t = $top->Toplevel; $t->title("Choose Directory(must be a project Directory)"); # my $t = $top->Frame; my $ok = 0; # flag: "1" means OK, "-1" means cancelled # Create Frame widget before the DirTree widget, so it's always visible # if the window gets resized. my $f = $t->Frame->pack(-fill => "x", -side => "bottom"); #my $curr_dir = Cwd::cwd(); my $curr_dir = 'k:/'; my $d; $d = $t->Scrolled('DirTree', -scrollbars => 'osoe', -width => 60, -height => 20, -selectmode => 'browse', -exportselection => 1, -browsecmd => sub { $curr_dir = shift }, # With this version of -command a double-click will # select the directory #-command => sub { $ok = 1 }, # With this version of -command a double-click will # open a directory. Selection is only possible with # the Ok button. -command => sub { $d->opencmd($_[0]) } )->pack(-fill => "both", -expand => 1); # Set the initial directory $d->chdir($curr_dir); $d->chdir('c:/'); $f->Button(-text => 'Ok', -command => sub{$ok = 1} )->pack(-side => 'left', qw/-padx 50 -ipadx 10/); $f->Button(-text => 'Cancel', -command => sub {$ok = -1})->pack(-side => 'right',qw/-pady 3 -padx 50/); $top->bind('',[$top=>'destroy']); $t->bind('',sub{$ok=3}); $f->bind('',sub{$ok=3}); # You probably want to set a grab. See the Tk::FBox source code for # more information (search for grabCurrent, waitVariable and # grabRelease). $f->waitVariable(\$ok); if ($ok == 1) { warn "The resulting directory is: $curr_dir\n"; }#elsif($ok == -1){exit(0);} else{print"No directory chosen.\n";goto TOP;} $top => 'destroy'; return ($curr_dir);