in reply to Re: Perl-tk Entry
in thread Perl-tk Entry

First of all thanks for the quick response. I tried what you said with no luck... this is my code:
use strict; use Tk; my $main = MainWindow->new; $main->minsize(qw(350 350)); $main->title("GUI"); $main->configure(); my $left3 = $main->Frame()->pack(-side=>'left'); my $padchk=0; if ($padchk==1) {$padchk=1;} else {$padchk=0;} my $padchk = $left3->Checkbutton(-variable=>\$padchk,-command=> sub{op +en_menu($padchk)})->pack(); MainLoop; sub open_menu { my $padchk= shift; my $gdsPath= shift; my $text=$left3->Label(-text=> 'enter your name:', -background=>'white +'); my $gdsPath=$left3->Entry(); if ($padchk==1){ $text->pack(); $gdsPath->pack(); } elsif ($padchk==0){ $text->destroy; $gdsPath->destroy; $left3->update; } }
If you'll run it you'll see that each time you turn it on new entry appears but when you turn it off, it doesnt disappear. Thanks again!

Replies are listed 'Best First'.
Re^3: Perl-tk Entry
by Limbic~Region (Chancellor) on Jul 16, 2008 at 23:28 UTC
    erez_ez,
    You really should use warnings. What I have does what you want, but is really a bad way of doing it - you should look at the advice from zentara. I only had a couple of minutes in between playing blocks with my 2 year old.
    #/usr/bin/perl use strict; use warnings; use Tk; my $main = MainWindow->new; $main->minsize(qw(350 350)); $main->title("GUI"); $main->configure(); my $l_frame = $main->Frame()->pack(-side => 'left'); my ($checked, $entry); my $check_box = $l_frame->Checkbutton( -variable => \$checked, -command => sub { open_menu($checked, \$entry); } )->pack(); MainLoop; sub open_menu { my ($checked, $entry) = @_; if ($checked) { $$entry = $l_frame->Label( -text => 'enter your name: ', -background => 'white' ) if ! defined $$entry; $$entry->pack(); } else { $$entry->destroy; $$entry = undef; $main->update; } }

    Cheers - L~R