RE: A Perl::Tk question
Thanks Jack, yes another member suggested method 1 and I am going to be using that. The reason for using this is that a legacy app ( no source, probably VB) was giving clients a text box with a 5 box choice as to what they wanted to do with the input, so each box press would slightly modify the calling parameters to a subsequent program. The clients do not want to use command line options, so this little app will give them the same look and feel and now we'll have some source code to go along with it. Thanks again. Alex -Original Message- From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Jack Sent: Monday, February 23, 2009 3:47 PM To: perl-win32-users@listserv.activestate.com Subject: RE: A Perl::Tk question Sorry for the top post - it's just how my reader works. There are two options here. The first is to pass the number as an argument to your subroutine. The second is to get the widget reference itself. It all depends on what information you *really* need and why you need it. i.e. It makes no sense to have 3 buttons doing the same thing unless you are passing different information. Examples - ## #Method #1: ## use Tk; use strict; my $mw=tkinit; foreach (1..3) { $mw->Button(-text=>"Button $_", -command=>[\&display,$_])->pack; } MainLoop; sub display { my ($num) = @_; print $num,"\n"; } ## #Method #2: ## use Tk; use strict; my $mw=tkinit; foreach (1..3) { $mw->Button(-text=>"Button $_", -command=>\&display)->pack; } MainLoop; sub display { print "\$Tk::event = ", $Tk::event,"\n"; print "\$Tk::widget = ", $Tk::widget,"\n"; print "A way to get widget through the event", $Tk::event->W,"\n"; } ## There is a third option where if you bind to say Button-Release, then the widget reference will be implicitly passed in the argument list. But method 1 or 2 should work for your needs. Jack -Original Message- From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of alex.ign...@atcoitek.com Sent: February-23-09 1:59 PM To: perl-win32-users@listserv.activestate.com Subject: A Perl::Tk question Hi there, I need to know the name of the object that called me from inside my callback routine. For instance I have 3 buttons, they all call the same subroutine, if button number 3 was pressed, I want to be able to determine that at run time. Even if it's just by reading the button text. How do I do this? ( small example snippet ) my $button1 = $mw->Button(-text => 'button#1',-command => \&display) my $button2 = $mw->Button(-text => 'button#2',-command => \&display) my $button3 = $mw->Button(-text => 'button#3',-command => \&display) sub display { print "I was called by button ???\n"; } This is probably some simple thing that I am not finding at the moment. I've tried googling this all over the place and can't seem to make any headway. Thanks in advance Alex The information transmitted is intended only for the addressee and may contain confidential, proprietary and/or privileged material. Any unauthorized review, distribution or other use of or the taking of any action in reliance upon this information is prohibited. If you receive this in error, please contact the sender and delete or destroy this message and any copies. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs No virus found in this incoming message. Checked by AVG - www.avg.com Version: 8.0.237 / Virus Database: 270.11.3/1966 - Release Date: 02/22/09 17:21:00 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: A Perl::Tk question
You need to pass argument to the display function, try the following: my $button1 = $mw->Button(-text => 'button#1',-command => [\&display, ARG_PASSING_TO_DISPALY]) --Kfir -Original Message- From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of alex.ign...@atcoitek.com Sent: Monday, February 23, 2009 10:59 PM To: perl-win32-users@listserv.ActiveState.com Subject: A Perl::Tk question Hi there, I need to know the name of the object that called me from inside my callback routine. For instance I have 3 buttons, they all call the same subroutine, if button number 3 was pressed, I want to be able to determine that at run time. Even if it's just by reading the button text. How do I do this? ( small example snippet ) my $button1 = $mw->Button(-text => 'button#1',-command => \&display) my $button2 = $mw->Button(-text => 'button#2',-command => \&display) my $button3 = $mw->Button(-text => 'button#3',-command => \&display) sub display { print "I was called by button ???\n"; } This is probably some simple thing that I am not finding at the moment. I've tried googling this all over the place and can't seem to make any headway. Thanks in advance Alex The information transmitted is intended only for the addressee and may contain confidential, proprietary and/or privileged material. Any unauthorized review, distribution or other use of or the taking of any action in reliance upon this information is prohibited. If you receive this in error, please contact the sender and delete or destroy this message and any copies. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: A Perl::Tk question
Sorry for the top post - it's just how my reader works. There are two options here. The first is to pass the number as an argument to your subroutine. The second is to get the widget reference itself. It all depends on what information you *really* need and why you need it. i.e. It makes no sense to have 3 buttons doing the same thing unless you are passing different information. Examples - ## #Method #1: ## use Tk; use strict; my $mw=tkinit; foreach (1..3) { $mw->Button(-text=>"Button $_", -command=>[\&display,$_])->pack; } MainLoop; sub display { my ($num) = @_; print $num,"\n"; } ## #Method #2: ## use Tk; use strict; my $mw=tkinit; foreach (1..3) { $mw->Button(-text=>"Button $_", -command=>\&display)->pack; } MainLoop; sub display { print "\$Tk::event = ", $Tk::event,"\n"; print "\$Tk::widget = ", $Tk::widget,"\n"; print "A way to get widget through the event", $Tk::event->W,"\n"; } ## There is a third option where if you bind to say Button-Release, then the widget reference will be implicitly passed in the argument list. But method 1 or 2 should work for your needs. Jack -Original Message- From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of alex.ign...@atcoitek.com Sent: February-23-09 1:59 PM To: perl-win32-users@listserv.activestate.com Subject: A Perl::Tk question Hi there, I need to know the name of the object that called me from inside my callback routine. For instance I have 3 buttons, they all call the same subroutine, if button number 3 was pressed, I want to be able to determine that at run time. Even if it's just by reading the button text. How do I do this? ( small example snippet ) my $button1 = $mw->Button(-text => 'button#1',-command => \&display) my $button2 = $mw->Button(-text => 'button#2',-command => \&display) my $button3 = $mw->Button(-text => 'button#3',-command => \&display) sub display { print "I was called by button ???\n"; } This is probably some simple thing that I am not finding at the moment. I've tried googling this all over the place and can't seem to make any headway. Thanks in advance Alex The information transmitted is intended only for the addressee and may contain confidential, proprietary and/or privileged material. Any unauthorized review, distribution or other use of or the taking of any action in reliance upon this information is prohibited. If you receive this in error, please contact the sender and delete or destroy this message and any copies. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs No virus found in this incoming message. Checked by AVG - www.avg.com Version: 8.0.237 / Virus Database: 270.11.3/1966 - Release Date: 02/22/09 17:21:00 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs