ckj has asked for the wisdom of the Perl Monks concerning the following question:

I want to develop a GUI where there should be a screen and two buttons, when the script is run that screen has some value through, suppose buttons are x & Y. When I click on x then according to x the values on that screen changes and when we click on Y the values should change according to Y. My problem is that I'm able to get different screen on clicks with those values but I'm not getting how to override the same screen with different values on click.
#!/wperl use strict; use warnings; use Tk; use Tk::Animation; my $mw = new MainWindow(-background=>'#3B5998', -title=>'GUI - @CKJ'); $mw->geometry('100x100+40+50'); #GUI Building Area #Default Settings my $frm_q1 = $mw -> Frame()-> pack(-side => 'top', -expand => 1, -fill + => 'x'); my $lbl_q1 = $frm_q1 -> Label(-text=>"Choose color")-> pack(-side => ' +left'); my $rdb_p = $frm_q1 -> Radiobutton(-text=>"Red",-value=>"1", -variabl +e=>"arg_02")-> pack(-side => 'left'); my $rdb_f = $frm_q1 -> Radiobutton(-text=>"Green",-value=>"2",-variabl +e=>"arg_02")-> pack(-side => 'left'); my $rdb_o = $frm_q1 -> Radiobutton(-text=>"Blue",-value=>"3",-variable +=>"arg_02")-> pack(-side => 'left'); my $but = $mw -> Button(-text=>"Preferred color", -command =>\&push_bu +tton)->pack(); my $but1 = $mw -> Button(-text=>"Submit", -command =>\&update_script)- +>pack(); MainLoop;
In this program when the user clicks on "Preferred color" button then those radio buttons should be disable and only the preferred color should be selected. When the user clicks on submit, then all the radio button should be disable with a message that your change has been accepted.

Replies are listed 'Best First'.
Re: Need suggestion in perl TK
by zentara (Cardinal) on Jul 05, 2012 at 08:42 UTC
    Here is a suggestion that shows you the basic idea. It's not exactly what you ask for, but this is not a free code writing service. :-)
    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new; my $lastbutton = 'blue'; my $rb = 'blue'; my $rb1 = $mw->Radiobutton(-text => "Button Blue", -value => 'blue', -variable => \$rb, -command => [ \&showRB, \$rb ])->pack; my $rb2 = $mw->Radiobutton(-text => "Button Red", -value => 'red', -variable => \$rb, -command => [ \&showRB, \$rb ])->pack; my $rb3 = $mw->Radiobutton(-text => "Button Green", -value => 'green', -variable => \$rb, -command => [ \&showRB, \$rb ])->pack; my $rb4 = $mw->Radiobutton(-text => "Button Hot Pink", -value => 'hotpink', -variable => \$rb, -command => [ \&showRB, \$rb ])->pack; my $but = $mw -> Button(-text=>"Preferred color", -command =>\&push_bu +tton)->pack(); my $but1 = $mw -> Button(-text=>"Submit", -command =>\&update_script)- +>pack(); MainLoop; sub push_button { foreach my $rb( $rb1,$rb2,$rb3, $rb4){ $rb->configure(-state => 'disabled'); } $mw->messageBox(-title => 'Status', -type => 'OK', -message => "Status is :$rb:. Previous State was + $lastbutton"); } sub update_script{ $but1->configure(-bg => $rb); } sub showRB { print "Arg list is @_\n"; my $state_ref = shift; my $state = $$state_ref; $mw->messageBox(-title => 'Status', -type => 'OK', -message => "Status is :$state:. Previous State +was $lastbutton"); $lastbutton = $state; }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      Thanks zentara it's working fine. Thanks a ton :)
Re: Need suggestion in perl TK
by Anonymous Monk on Jul 05, 2012 at 07:11 UTC

    In this program when the user clicks on "Preferred color" button then those radio buttons should be disable and only the preferred color should be selected. When the user clicks on submit, then all the radio button should be disable with a message that your change has been accepted.

    How about you show that part of your program ?