CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
closing TK window

 



droidus2
Novice

Nov 13, 2015, 3:39 AM

Post #1 of 2 (1330 views)
closing TK window Can't Post

Here is my code:


Code
$guiBrowseSelec = guiBrowse(); 
print "You selected the $guiBrowseSelec folder. Is this correct? [Y/N]: ";
$response = <>;
chomp($response);

sub guiBrowse
{
my $top = new MainWindow;
$top->withdraw;

my $t = $top->Toplevel;
$t->title("Choose directory:");
my $ok = 0;

my $f = $t->Frame->pack(-fill => "x", -side => "bottom");

my $curr_dir = 'd:';
#my $curr_dir = Cwd::cwd();

my $d;
$d = $t->Scrolled('DirTree',
-scrollbars => 'osoe',
-width => 35,
-height => 20,
-selectmode => 'browse',
-exportselection =>1,
-browsecmd => sub { $curr_dir = shift },
-command => sub { $ok = 1; },
)->pack(-fill => "both", -expand => 1);

$d->chdir($curr_dir);

$f->Button(-text => 'Ok',
-command => sub { $ok = 1 })->pack(-side => 'left');
$f->Button(-text => 'Cancel',
-command => sub { $ok = 1 })->pack(-side => 'left');

$f->waitVariable(\$ok);

return $curr_dir;
}


When I click "ok" after selecting a folder, it shows the "ok" button pushed in, but the window does not close, but it goes to this prompt:

Code
print "You selected the $guiBrowseSelec folder.  Is this correct? [Y/N]: ";


How do I get the window to close after the ok/cancel button is clicked?


FishMonger
Veteran / Moderator

Nov 13, 2015, 6:49 AM

Post #2 of 2 (1323 views)
Re: [droidus2] closing TK window [In reply to] Can't Post

You need to withdraw the window. Add this statement just before the return.

Code
$t->withdraw;


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives