NirMH NirMH - 2 years ago 75
Perl Question

How to create a menu check button in checked mode in perl Tk?

I would like to create a menubar checkbutton in a "checked" state.

It seems that creating the menubar checkbutton according to the documentation will create it in an "unchecked" state.

How can i create it in a "checked" state (or onvalue state)?

Answer Source

Check the widget demo, click on Menus / 1. Menus and cascades (sub-menus). When you click on Cascades there, click on Check Buttons - two of the check buttons are checked. The relevant code is located in

my $cc = $c->cascade(-label => '~Check buttons', -tearoff => 0);

$cc->checkbutton(-label => 'Oil checked', -variable => \$OIL);
$cc->checkbutton(-label => 'Transmission checked', -variable => \$TRANS);
$cc->checkbutton(-label => 'Brakes checked', -variable => \$BRAKES);
$cc->checkbutton(-label => 'Lights checked', -variable => \$LIGHTS);
# ...
my $cc_menu = $cc->cget(-menu);

Setting the variables to the respective onvalues also works.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download