in reply to Tk Checkbutton

You would be better off making your own widget on a sub-classed Canvas. However you could bind a right mouse button click to each checkbutton, to simulate 3 states.
#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Pane; my @states = qw(Alaska Hawaii Michigan Georgia Arizona Washington Oreg +on California Texas Utah Minnesota); my $mw = tkinit(); $mw->geometry('300x300+100+100'); my $sp = $mw->Scrolled('Pane', -scrollbars=>'osoe', sticky=>'nwse') ->pack(-expand=>1, -fill=>'both' ); my %cbs; my @cbvalues; my @cbnames; my $count = 0; foreach my $d( @states){ $cbnames[$count] = $d; $cbs{$count} = $sp->Checkbutton(-text => $d, -font=>[arial => 12], -onvalue => 1, -offvalue => 0, -variable => \$cbvalues[$count], -font => 'big', -bg => 'white', )->pack(-anchor=>'w')->pack(); $cbs{$count}->bind('<ButtonRelease-3>', sub{ print "@_\n"; print "do you 3rd state thing here\n"; }); $count++; } my $showbutton= $mw->Button(-text=>'Show Selected', -bg => 'lightyellow', -command => sub{ my @selected = (); foreach my $c( 0.. $count ){ if ( $cbvalues[$c] ){ push @selected, $cbnames[$c]; } } print "@selected\n"; } )->pack(); MainLoop();

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^2: Tk Checkbutton
by ak.arjun (Initiate) on Apr 25, 2012 at 05:34 UTC

    Well making my own widget is an option, and can't use right mouse click because my requirement is to make a hierarchical tree structure with each entry of tree containing a check-button. Hence whenever each check-button is selected all its child node should get selected, but when de-select a check-button, the parent check-button will get partially de-selected(third state) or or totally de-selected(only if all its child node are de-selected))

    What i was thinking that each check-button has a variable associated to it, and when i change the value of that variable to on/off state, the check-button gets selected/de-selected automatically. So if i know how does tk is exactly implementing this behavior, i can make changes in that area of code to add my functionality. Is it possible?