## LoginForm.pm package LoginForm; use strict; use base qw(Tk::Frame); Tk::Widget->Construct('LoginForm'); sub Populate { my ($cw, $args) = @_; $cw->SUPER::Populate($args); my $f = $cw->Frame->pack; my $msg = $f->Label-> grid(qw/-columnspan 2 -sticky ew/); my $userE = $f->Entry; $f->Label(-text => "User:")-> grid($userE, -sticky => 'e'); my $passE = $f->Entry(-show => '*'); $f->Label(-text => "Password:")-> grid($passE, -sticky => 'e'); my $button = $f->Button( -text => 'Login', -command => [Login => $cw] )->grid(qw/-columnspan 2 -pady 4/); $cw->Advertise(Message => $msg); $cw->Advertise(UserEntry => $userE); $cw->Advertise(PassEntry => $passE); $cw->Advertise(LoginButton => $button); } sub Login { my $cw = shift; my $user = $cw->Subwidget('UserEntry')->get; my $pass = $cw->Subwidget('PassEntry')->get; print "$user/$pass\n"; } 1; ## login.pl use Tk; use LoginForm; my $mw = MainWindow->new; $mw->LoginForm->pack; MainLoop;