Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^4: How to disable the buttons

by vr786 (Sexton)
on Nov 04, 2010 at 07:21 UTC ( [id://869408]=note: print w/replies, xml ) Need Help??


in reply to Re^3: How to disable the buttons
in thread How to disable the buttons

Thanks for giving replay, here is my code , in that two option menus , one button is there , what i want is , if the first optionmenu selected the second one get activated , if the second one get selected the exit button should get activated till then optionmenu2,exit button are disabled state how i do it please help me..........

#!/usr/bin/perl -w use Tk; my $mw = MainWindow->new(); $mw-> geometry("400x100"); $mw -> configure(-background => "cyan", -foreground => "lightblue" ); my $opt = "0"; my $opt1 = "0"; my ($var, $tvar); $opt = $mw->Optionmenu( -background => "lightgreen", -options => [[jan=>1], [feb=>2], [mar=>3], [apr=>4]], -command => sub { print "got: ", shift, "\n" }, -variable => \$var, -textvariable => \$tvar )->pack; $opt->configure(-state); #$opt->configure(-state=>'disabled'); $opt->addOptions([may=>5],[jun=>6],[jul=>7],[aug=>8]); my $exit_but = $mw->Button(-text=>'Exit', -command=>sub{$mw->destroy}) +->pack(-side=>"bottom"); $exit_but->configure(-state); $exit_but->configure(-state => 'disabled'); $opt1 = $mw->Optionmenu( -background => "lightgreen", -options => [qw(test1 test2 test3)], -command => \&do_some, -variable => \$var, )->pack; $opt1->configure(-state); MainLoop; sub do_some { if($opt ) { $exit_but -> configure(-state => 'disabled'); } else { $opt->configure(-state=>'disabled'); $opt1->configure(-state=>'active'); } }

Replies are listed 'Best First'.
Re^5: How to disable the buttons
by zentara (Archbishop) on Nov 04, 2010 at 11:37 UTC
    You have to be careful about the optionmenu widgets being in existence, before configuring their commands, when you want to set their state. This does what I think you want. It might also be good to have a Reset button so the button states can be restored, in case the user wants to redo the selections.
    #!/usr/bin/perl -w use strict; use Tk; my $mw = MainWindow->new(); $mw-> geometry("400x100"); $mw -> configure(-background => "cyan", -foreground => "lightblue" ); my ($var, $var1); my $opt = $mw->Optionmenu( -background => "lightgreen", -options => [[jan=>1], [feb=>2], [mar=>3], [apr=>4]], -variable => \$var, )->pack; $opt->addOptions([may=>5],[jun=>6],[jul=>7],[aug=>8]); my $exit_but = $mw->Button(-text=>'Exit', -command=>sub{ print "Var= $var Var1= $var1\n"; $mw->destroy}, -state => 'disabled', )->pack(-side=>"bottom"); my $opt1 = $mw->Optionmenu( -background => "lightgreen", -options => [qw(test1 test2 test3)], -variable => \$var1, -state => 'disabled', )->pack; # must configure the $opt command AFTER $opt1 gets created $opt->configure(-command => sub{ print "got: ", shift, "\n"; $opt->configure(-state => 'disabled'); $opt1->configure(-state => 'normal'); }); $opt1->configure( -command => sub{ $opt1->configure(-state => 'disabled'); $exit_but->configure(-state => 'normal'); }); MainLoop;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://869408]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-23 10:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found