Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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.

Replies are listed 'Best First'.
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?
[karlgoethebier]: Discipulus: see also Re: poll ideas quest 2017

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2017-06-26 09:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (575 votes). Check out past polls.