Thread Perl/TK - Viele Checkboxes korrekt anzeigen (1 answers)
Opened by oip at 2012-09-28 10:21

Gast oip
 2012-09-28 10:21
#162129 #162129
Hi allerseits,

ich hab folgendes Problem:

Ich will in einem neuen MainWindow ca. 8000 Checkboxes anzeigen lassen und dieses MainWindow ist auch scrolled. Jedoch werden die Checkboxes und deren Labels nicht richtig dargestellt bzw. nur Bruchstücke.

Muss ich einen Delay einbauen oder etwas ähnliches?
Über Problemlösungen würde ich mich freuen.

more (5.8kb):

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
 $defineSerialsWindow = new MainWindow;
$defineSerialsWindow->title ("select Serial(s)");
$defineSerialsWindow->geometry("1300x1000");
$defineSerialsWindow->resizable( 1, 1 );

my $img_icon = $defineSerialsWindow->Photo(-file=>$current_folder."\\img\\".'logo_ux.png');
$defineSerialsWindow->Icon(-image=>$img_icon);

#scrollbar, because the window defineCustomerWindow is to small for showing all entries
my $pane = $defineSerialsWindow->Scrolled('Pane', Name => 'Button_Window',
-scrollbars => 'soe',
-sticky => 'we',
-gridded => 'y'
);



#all labels and checkboxes are anchored at the new widget $pane to add a scrollbar
my $label_selectAll_serials = $pane->Label (-text => 'select all');
my $checkbox_selectAll_serials = $pane->Checkbutton ( -command => \&select_all_serials, -variable => \$select_all_serials);
$checkbox_selectAll_serials->deselect();


my $label_deselectAll_serials = $pane->Label (-text => 'deselect all');
my $checkbox_deselectAll_serials = $pane->Checkbutton ( -command => \&deselect_all_serials, -variable => \$deselect_all_serials);
$checkbox_deselectAll_serials->deselect();

my $save_button_serials = $pane->Button (-text => 'Save & Exit', -command => \&save_exit_serials,-foreground =>'red',-background =>'black');

# close window if [x] is pressed and uncheck
$defineSerialsWindow->protocol(
'WM_DELETE_WINDOW',
sub {
$defineSerialsWindow->withdraw();
return;
}
);

############################Einlesen der Seriennummern aus Artis_31-01-2012.xls#######################

my $label_listingSerials;
my $line = undef;
my @defineserials = "";
my @checkboxarray = undef;
my $checkbox_listingSerials;

my @label_listingSerials = undef;
my @checkbox_listingSerials = undef;

# Open File and Worksheet
my $Book = $Excel->Workbooks->Open
($current_folder."\\data\\".'Artis_31-01-2012.xls'); # open Excel file
my $Sheet = $Book->Worksheets(1);

my $array = $Sheet->Range("B2:B8012")->{'Value'};
foreach my $ref_array (@$array)
{
foreach my $scalar (@$ref_array)
{
push(@defineserials, $scalar);

}
}

$Book->Close; # close excelsheet

# sort entries lexically
@defineserials = sort @defineserials;

# define no of rows and columns, number of rows is hard-coded (50), could be smaller ??
my $amount_rows = 500;
my $amount_col = ($#defineserials/$amount_rows)+1;
my @var_serial; #checkbutton checked or unchecked ? : checked => $var = 1; unchecked => $var = 0

###### pack widgets (labels and checkboxes in right columns and rows)
my $cnt_entries = 1;

LOOPEntries: for my $col_ctr(0..$amount_col)
{
for my $row_ctr(2..$amount_rows)
{
# put values to variable and take the counter for the packing of the widgets (checkbox, label)

$label_listingSerials[$cnt_entries] = $pane->Label(-text=> $defineserials[$cnt_entries]);
$checkbox_listingSerials[$cnt_entries] = $pane->Checkbutton (-command =>[\&used_serials, $defineserials[$cnt_entries], $cnt_entries], -variable => \$var_serial[$cnt_entries], -onvalue => 1, -offvalue =>0);

#pack the widgets on the pane
$label_listingSerials[$cnt_entries]->grid(-row=>$row_ctr, -column=>$col_ctr*2+1, -sticky=>'w');
$checkbox_listingSerials[$cnt_entries]->grid(-row=>$row_ctr, -column=>$col_ctr*2);

push(@checkboxarray, $checkbox_listingSerials[$cnt_entries] );

$cnt_entries++;

if ($cnt_entries == $#defineserials+1) #modified by FDu - 10.09.2012 => last index missing; old: $#defineserials; new: $#defineserials+1
{
last LOOPEntries;
}
}

}

$checkbox_selectAll_serials->grid(-row=>0, -column=>0);
$label_selectAll_serials->grid(-row=>0, -column=>1, -sticky=>'w');
$checkbox_deselectAll_serials->grid(-row=>1, -column=>0);
$label_deselectAll_serials->grid(-row=>1, -column=>1, -sticky=>'w');
$save_button_serials->grid(-row => 0, -column => 2, -padx => 4);

$pane->pack(-fill => 'both', -expand => 1);
more (0b):


modedit Editiert von GwenDragon: MORE-Tag um Code, Titel ergänzt
Last edited: 2012-09-28 10:28:13 +0200 (CEST)

View full thread Perl/TK - Viele Checkboxes korrekt anzeigen