Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Aligning Tk Checkboxes

by zentara (Archbishop)
on Sep 13, 2012 at 10:56 UTC ( #993449=note: print w/ replies, xml ) Need Help??


in reply to Aligning Tk Checkboxes

You might want to look at Tk::CheckbuttonGroup which does alignments.


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


Comment on Re: Aligning Tk Checkboxes
Re^2: Aligning Tk Checkboxes
by roho (Monsignor) on Sep 13, 2012 at 15:01 UTC
    Thanks for the suggestion. I installed the module, ran the code in the synopsis (after adding use TK; at the top and MainLoop; at the bottom), and got a blank Tk screen. Unfortunately the documentation is quite sparse. Do you happen to have a working sample of this module? It appears to be exactly what I need. Thanks.

    "Its not how hard you work, its how much you get done."

      #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::CheckbuttonGroup; my $top = MainWindow->new(); $top->geometry('400x400'); my @selected = qw(two four); my $checkbuttongroup = $top->CheckbuttonGroup ( -font => 24, -list => [qw( one two three four five )], -orientation => 'vertical', -variable => \@selected, -command => sub { print @selected, "\n"; } )->pack(); my @selected1 = qw(8 10); my $checkbuttongroup1 = $top->CheckbuttonGroup ( -font => 24, -list => [qw( 6 7 8 9 10 )], -orientation => 'horizontal', -variable => \@selected1, -command => sub { print @selected1, "\n"; } )->pack(); MainLoop;

      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku ................... flash japh
        Thanks zentara. The Tk::CheckbuttonGroup module works great! It looks like the synopsis code was missing "pack". Unfortunately, I just found out I'm not going to be able to install additional CPAN modules at deployment sites (sigh), so (taking a cue from the module) I re-worked the frames in my original code to display two vertically aligned columns of checkboxes using only Tk (see new code below). Thanks for all your help.

        #!/usr/bin/perl use strict; use warnings; use Tk; my $mw = MainWindow->new(); $mw->geometry('360x250+280+60'); $mw->bind('<Escape>' => sub {exit;}); $mw->configure(-title => 'Test Checkbox Alignment'); my ($qv, $dg, $yb, $pv, $rd, $oc, $hr, $tm); ################################################################### # Create buffer 1. ################################################################### my $buffer1 = $mw->Frame; $buffer1->pack(-side => 'left', -padx => 25); ################################################################### # Create frame 1. ################################################################### my $frame1 = $mw->Frame; $frame1->pack(-side => 'left'); ################################################################### # Create check box 1 for frame 1. ################################################################### my $qv_cbox = $frame1->Checkbutton( -text => 'QuickCheck', -variable => \$qv, ); $qv_cbox->pack( -side => 'top', -anchor => 'w', ); ################################################################### # Create check box 2 for frame 1. ################################################################### my $dg_cbox = $frame1->Checkbutton( -text => 'Systems Guide', -variable => \$dg, ); $dg_cbox->pack( -side => 'top', -anchor => 'w', ); ################################################################### # Create check box 3 for frame 1. ################################################################### my $yb_cbox = $frame1->Checkbutton( -text => 'Study', -variable => \$yb, ); $yb_cbox->pack( -side => 'top', -anchor => 'w', ); ################################################################### # Create check box 4 for frame 1. ################################################################### my $pv_cbox = $frame1->Checkbutton( -text => 'Analyze', -variable => \$pv, ); $pv_cbox->pack( -side => 'top', -anchor => 'w', ); ################################################################### # Create buffer 2. ################################################################### my $buffer2 = $mw->Frame; $buffer2->pack(-side => 'left', -padx => 25); ################################################################### # Create frame 2. ################################################################### my $frame2 = $mw->Frame; $frame2->pack(-side => 'left'); ################################################################### # Create check box 1 for frame 2. ################################################################### my $rd_cbox = $frame2->Checkbutton( -text => 'Read', -variable => \$rd, ); $rd_cbox->pack( -side => 'top', -anchor => 'w', ); ################################################################### # Create check box 2 for frame 2. ################################################################### my $oc_cbox = $frame2->Checkbutton( -text => 'Configure', -variable => \$oc, ); $oc_cbox->pack( -side => 'top', -anchor => 'w', ); ################################################################### # Create check box 3 for frame 2. ################################################################### my $hr_cbox = $frame2->Checkbutton( -text => 'Troubleshoot', -variable => \$hr, ); $hr_cbox->pack( -side => 'top', -anchor => 'w', ); ################################################################### # Create check box 4 for frame 2. ################################################################### my $tm_cbox = $frame2->Checkbutton( -text => 'Prioritize', -variable => \$tm, ); $tm_cbox->pack( -side => 'top', -anchor => 'w', ); MainLoop; exit;

        "Its not how hard you work, its how much you get done."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://993449]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (15)
As of 2014-09-16 20:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (46 votes), past polls