Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2023-03-22 00:47 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.