Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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 cooling their heels in the Monastery: (11)
As of 2014-07-31 08:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (245 votes), past polls