in reply to Binding an action to an item in a Listbox

Hey all,
Thanks for all the help so far.
Listen I have a new problem. When you go and click on open to open a file the open window pops up. You select a file, its name appears in the entry bar and you click open. Now this loads the file, but the window stays open. How can I get it to close when you click on open as well as loading the sub "load"??
I tried this, but to no avail.
$name = $bf->Entry(-textvariable => \$filename); my $button = $bf->Button( -command => \&load, -text => 'Open'); $tf->pack(-side => 'top'); $bf->pack(-side => 'bottom'); $ListBox->pack(qw/-side left -fill both -expand 1/); $name->pack(-anchor => 's'); $button->pack(-anchor => 'se'); } sub load{ my ($index) = $ListBox->curselection(); $filename = $ListBox->get($index); $mw->configure(-title => 'TextEd - ' . $filename); [ $open => 'destroy']; $InputText->Load( $filename ); (my $script = $0) =~ s,.*(\/|\\),,; }
I also tried this.
$name = $bf->Entry(-textvariable => \$filename); my $button = $bf->Button( -command => \&load, -command =>[ $open => 'destroy'], -text => 'Open'); $tf->pack(-side => 'top'); $bf->pack(-side => 'bottom'); $ListBox->pack(qw/-side left -fill both -expand 1/); $name->pack(-anchor => 's'); $button->pack(-anchor => 'se'); } sub load{ my ($index) = $ListBox->curselection(); $filename = $ListBox->get($index); $mw->configure(-title => 'TextEd - ' . $filename); $InputText->Load( $filename ); (my $script = $0) =~ s,.*(\/|\\),,; }
I'm kina running ow on ideas..
Any suggestions???
Thanks

All the Best, Eoin...

If everything seems to be going well, you obviously don't know what the hell is going on.

Replies are listed 'Best First'.
Re: Re: Binding an action to an item in a Listbox
by tall_man (Parson) on Apr 18, 2003 at 15:19 UTC
    Hi eoin. With pop-up dialogs like this which the user may open and close several times, it's often a good idea to hold onto them and not create and destroy them each time. So if you say this within sub load:
    $open->withdraw();
    And also test in the routine where you create $open:
    if (defined $open) { $open->deiconify(); } else { # create the dialog window here }
    That should do the trick. Make sure $open is a my variable at the top scope level instead of just within the routine, of course.