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 \&
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); }
|
---|
In Section
Seekers of Perl Wisdom