Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

How to keep two checkbuttons in sync

by ghosh123 (Monk)
on Mar 27, 2013 at 17:45 UTC ( #1025771=perlquestion: print w/ replies, xml ) Need Help??
ghosh123 has asked for the wisdom of the Perl Monks concerning the following question:

Hi
I have two checkbuttons (namely 'Main' and 'Top')in my perl tk application. One checkbutton is on the main gui and other is on a toplevel (popup) gui.
How can I keep both of them in sync

Following is the code:

use Tk; my $mw = MainWindow->new ; my ($m,$t); $mw->geometry("100x100"); $mw->Checkbutton(-text => 'Main',-variable=>\$m)->pack(-side => 'left' +); $mw->Button(-text => 'popup', -command => sub {my $t = $mw->Toplevel() +;$t->geometry("50x50");$t->Checkbutton(-text => 'Top',-variable => \$ +t)->pack(-side => 'left')})->pack(); MainLoop;

How can I keep 'Main' and 'Top' in sync. That means when 'top' is selected , 'Main' also gets selected and similarly when 'Top' is deselected
that makes also 'Main' deselected.

Comment on How to keep two checkbuttons in sync
Download Code
Re: How to keep two checkbuttons in sync
by Anonymous Monk on Mar 27, 2013 at 18:19 UTC

    You've already got a -variable linked to one of the checkboxes. Why not link it to both?

Re: How to keep two checkbuttons in sync
by gurpreetsingh13 (Scribe) on Mar 28, 2013 at 03:29 UTC
    Checkbutton manpage says: Name: offValue Class: Value Switch: -offvalue Specifies value to store in the button's associated variable whenever this button is deselected. Defaults to ``0''. Name: onValue Class: Value Switch: -onvalue Specifies value to store in the button's associated variable whenever this button is selected. Defaults to ``1''.

    As said by Anonymous monk, just link it to same variable and you are done:

    $t->Checkbutton(-text => 'Top',-variable => \$m)->pack(-side => 'left' +)})->pack();

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1025771]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-08-21 07:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (128 votes), past polls