Re: (fwd) How to make a megawidget with two entrys and two variables
Steve Lidie <[email protected]>
| Newsgroups | gmane.comp.lang.perl.tk |
|---|---|
| Message-ID | <[email protected]> |
> From: "Pit" <[email protected]> > Newsgroups: comp.lang.perl.tk > Subject: How to make a megawidget with two entrys and two variables > Date: Thu, 10 Mar 2005 13:24:38 -0500 > > > Hi Folks > > a question to designing a mega-widget. > > I would like to create a mega-widget that contains two simple entry's > and > accordingly two text-variables. > > the mega-widget should be created as follows: > > my $megawidget->MegaWidet(-var1 => \$var1, > -var2 => \$var2); > > How to process this into the mega-widget ? > > Has somebody any examples or other ways in order to check this ? > With a tiny bit of room for improvement ... #!/usr/local/bin/perl -w $Tk::MyMega::VERSION = '0.1'; package Tk::MyMega; use base qw/Tk::Frame/; use strict; Construct Tk::Widget 'MyMega'; sub Populate { my($self, $args) = @_; $self->SUPER::Populate($args); $self->{entry1} = $self->Entry->pack; $self->{entry2} = $self->Entry->pack; $self->ConfigSpecs( -variable1 => [qw/PASSIVE variable1 Variable1/, undef ], -variable2 => [qw/PASSIVE variable2 Variable2/, undef ], ); } # end Populate sub ConfigChanged { my( $self, $args ) = @_; foreach my $k (keys %$args) { if( my( $n ) = $k =~ /^-variable(\d+)$/ ) { $self->{"entry${n}"}->configure( -textvariable => $args->{$k} ); } } } # end ConfigChanged package main; use Tk; #use Tk::MyMega; use strict; my $mw = MainWindow->new; my $frog = 1; my $toad = 2; my $mm = $mw->MyMega( -background => 'white', -foreground => 'blue', -variable1 => \$frog, -variable2 => \$toad, )->pack; $mw->update; $mw->after( 2000, sub{ $frog++; $toad++ } ); MainLoop; -++**==--++**==--++**==--++**==--++**==--++**==--++**== This message was posted through the Stanford campus mailing list server. If you wish to unsubscribe from this mailing list, send the message body of "unsubscribe ptk" to [email protected]