Two different solutions:
- pack/grid hybrid: Use pack to position Pane and Label, and give pack the options to dynamically resize Pane. Use grid to position buttons within Pane.
Oops, kvale beat me to this one.
- pack only: Put each set of 4 radiobuttons in a Frame, and pack the frames into Pane.
Other general recommendations:
- For your button variables, in each row, use the same variable for each of the 4 buttons, otherwise pressing one won't clear the other three!
- For your button variables, use an array instead of soft-referenced global variables.
- Use warnings (or -w) and strict.
- Add use Tk::Pane to prevent the "Assuming 'require Tk::Pane;'" warning.
- If you are using grid, then make your first row Labels, to avoid having to label each button.
- Use Data::Dumper during testing to see the values of your input controls.
The code below demonstrates all the recommendations, and both solutions.
#!/usr/bin/perl -w
use strict;
use Tk;
use Tk::Pane;
# Set to 0 or 1 before running.
my $grid_method = 1;
my $mw = MainWindow->new( -title => "SACL Survey" );
my $pane = $mw->Scrolled(qw/Pane -scrollbars osow/)->pack(
-expand => 'yes',
-fill => 'both',
);
$mw->Label( -text => "... <insert directions here> ..." )->pack();
my @button_values;
if ($grid_method) {
foreach my $j (1..4) {
$pane->Label(
-text => $j,
)->grid(
-column => $j,
-row => 1,
);
}
foreach my $i (1..30) {
foreach my $j (1..4) {
$pane->Radiobutton(
-value => $j,
-variable => \$button_values[$i-1],
)->grid(
-column => $j,
-row => $i+1,
);
}
}
} else {
foreach my $i (1..30) {
my $frame = $pane->Frame->pack();
foreach my $j (1..4) {
$frame->Radiobutton(
-text => $j,
-value => $j,
-variable => \$button_values[$i-1],
)->pack(
-side => 'left',
);
}
}
}
MainLoop;
use Data::Dumper;
print Dumper \@button_values;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|