Code Comments
Programming Forum and web based access to our favorite programming groups.Hi, I have 2 buttons in my perl-tk script. they both point to the same callback sub (they have the same -command value). My question is how can I know inside the callback sub which button invoked it? I know that I can write 2 separate callback subs but my future program will have ~100 buttons - all calling the same callback sub... Thanks very much, Roey
Post Follow-up to this messageIn article <202be612-01f7-4959-860d-59cb2293727f@d21g2000prf.googlegroups.co
m>,
roeygroen@gmail.com says...
> Hi,
> I have 2 buttons in my perl-tk script. they both point to the same
> callback sub (they have the same -command value).
> My question is how can I know inside the callback sub which button
> invoked it?
> I know that I can write 2 separate callback subs but my future program
> will have ~100 buttons - all calling the same callback sub...
use strict;
use warnings;
use Tk;
my $label = '';
my $mw = tkinit;
my $l = $mw->Label(-textvariable => \$label, -width => 20)->pack;
for (0 .. 20) {
$mw->Button(-text => $_, -command => [\&Display, $_], -width => 2)->pack;
}
MainLoop;
sub Display {
$label = "You pressed button $_[0]";
}
--
Go to http://MarcDashevsky.com to send me e-mail.
Post Follow-up to this messageOn Mar 11, 4:42 pm, Marc Dashevsky <use...@MarcDashevsky.com> wrote:
> In article <202be612-01f7-4959-860d-59cb22937...@d21g2000prf.googlegroups.
com>,
> roeygr...@gmail.com says...
>
>
> use strict;
> use warnings;
> use Tk;
>
> my $label = '';
>
> my $mw = tkinit;
> my $l = $mw->Label(-textvariable => \$label, -width => 20)->pack;
> for (0 .. 20) {
> $mw->Button(-text => $_, -command => [\&Display, $_], -width => 2)->pa
ck;}
>
> MainLoop;
>
> sub Display {
> $label = "You pressed button $_[0]";
>
> }
>
> --
> Go tohttp://MarcDashevsky.comto send me e-mail.
Thanks!!
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.