My problem is that, I want to put that whole loop into a function because it will be performed by different parts of the script.my @items; for my $text ( qw( one two three four five six seven eight nine ten ) +) { my $label = $pane->Label( -text => $text, -anchor => 'w', -fg => '#000000', -bg => '#C0C0C0', -font => 'courier 20 normal', )->pack(-fill => 'x', -expand => 1); push @items, $label; $label->bind('<Button-1>' => sub { $_->configure( -bg => '#C0C0C0') for @items; #unhighlight e +verything $selectedtext = $text; $label->configure( -bg=>'#CCE8FF'); #highlight this } ); $label->bind('<Double-1>' => sub { if (${$label->cget("-font")} eq 'courier 20 normal') { $label->configure( -font => 'courier 20 bold', -fg +=>'#0000FF'); } else { $label->configure( -font => 'courier 20 normal', - +fg=>"black"); } } ); }
But doing so, those Bindings dont work anymore.my @items; InitializeList(); sub InitializeList { undef @items; for my $text ( qw( one two three four five six seven eight nine te +n ) ) { ... } }
It appears I am having parameter passing problem.sub BindButton1 { } sub BindDouble1 { }
In reply to Binding within a sub by jsteng
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |