#!/usr/bin/perl use strict; use Tk; use Data::Dumper; my $mw = MainWindow->new; for(0..4){ $mw->Button(-text => "Hello World$_", -command=>[\&change])->pack; } MainLoop; sub change { #Tk dosn't pass it's widget reference in callbacks #Only the bind() method will implicity pass a widget reference, and even #this default (and generally preferred) action can be defeated. #use $Tk::widget print "sub-input->@_\n"; my $caller = $Tk::widget; #print Dumper([$caller]); print "$caller "; print $caller->{'_TkValue_'},' '; my $text = $caller->cget('-text'); print "$text\n"; $caller->configure(-text=>"Hello Stranger"); } #### #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = tkinit; my $id = $mw->id; print "mainwindow->$id\n"; my $button = $mw->Button(-text =>'Exit', -command =>sub {Tk::exit;} )->pack(); my $buttonid = $button->id; print "button->$buttonid\n"; my $mwpath = $mw->pathname($id); print "mwpath->$mwpath\n"; my $buttonpath = $button->pathname($buttonid); print "buttonpath->$buttonpath\n"; MainLoop;