Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: perl/tk changing button commands

by Improv (Pilgrim)
on Apr 22, 2003 at 17:30 UTC ( #252324=note: print w/replies, xml ) Need Help??


in reply to perl/tk changing button commands

Some comments
  • I doubt you really mean to be adding all those new buttons everytime you click 'next', right? You might want to read up about how the Tk event loop works.
  • You had the syntax for -command incorrect. You either pass it an anonymous subroutine (as in the $button2 example below) or a code reference, with \&
See below for corrected code.
use warnings; use Tk; sub one; my $main = MainWindow->new; my $button; my $button2; my $label1; $label1 = $main->Text ( '-width'=>'50')->pack; $button = $main->Button( -text=>'next', -command=>\&one)->pack; $button2 = $main->Button( -text=>'quit', -command=>sub{exit;})->pack; our $foo = "0"; MainLoop; sub one { my $talk="Hey, that was click $foo\n"; $foo++; $label1 -> insert('1.0',$talk); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://252324]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2023-03-31 10:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (75 votes). Check out past polls.

    Notices?