in reply to Perl Tk Naming Convention
You are asking for objects.... an object is essentially a blessed hash, that can contain all sorts of methods and data. So you would have $obj1->{'frame1'}->{'button2'}
But there is an arcane underlying naming convention in Tk, in case you want to use it, for example:
or try this#!/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 ev +en #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"); }
if you want a simple example of how to make your own package or module, google for "perl tk derived mega", and see my educational example of a simple Tk module example at CanvasDirTree.... you can use it as a template for making your own.#!/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;
|
|---|