Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I have this loop. As it adds labels into a Pane, it binds <1> and <Double-1> to perform specific tasks.
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"); } } ); }
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; InitializeList(); sub InitializeList { undef @items; for my $text ( qw( one two three four five six seven eight nine te +n ) ) { ... } }
But doing so, those Bindings dont work anymore.


Moreso, I also want to isolate the bindings into separate subroutine on their own as well to compartmentalize everything for ease of maintenance:
sub BindButton1 { } sub BindDouble1 { }
It appears I am having parameter passing problem.

In reply to Binding within a sub by jsteng

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-26 00:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found