Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

which widget called my callback sub?
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

Report this thread to moderator Post Follow-up to this message
Old Post
roeygroen@gmail.com
03-12-08 12:17 AM


Re: which widget called my callback sub?
In 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Marc Dashevsky
03-12-08 12:17 AM


Re: which widget called my callback sub?
On 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!!

Report this thread to moderator Post Follow-up to this message
Old Post
roeygroen@gmail.com
03-12-08 12:17 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PerlTk archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:51 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.