Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

How to keep two checkbuttons in sync

by ghosh123 (Monk)
on Mar 27, 2013 at 17:45 UTC ( [id://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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-16 13:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found