in reply to Building an adaptable 'Entry Widget'
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11141523 use warnings; use Tk; use Tk::DialogBox; use Tk::Frame; { ## OPEN package package Tk::GUIask; use List::Util qw(first); use base qw/Tk::Frame /; Construct Tk::Widget 'GUIask'; ## INSTALL MyNewWidget in pTk namespace sub ClassInit ## Called once to intitalise new class { my ($class , $mw ) = @_; $class ->SUPER::ClassInit($mw); } sub Populate { my ($self , $args ) = @_; my $tv = delete $args->{-textvariable}; # NOTE $self ->SUPER::Populate($args) ; require Tk::Entry; # $self -> SUPER::Populate($args); ## NEEDED? my $search = ""; my $frame = $self -> Frame( -borderwidth => 5, -relief => 'ridge', ) -> pack(); my $label = $frame -> Label ( -fg => 'blue', -font => 30 ) -> pack(-fill => 'x' ); my $entry = $frame -> Entry( -textvariable => $tv, # NOTE ) -> pack(-fill => 'x'); my $button = $frame -> Button ( -background => 'Red', -text => "Abort", -command => sub { ($frame -> destroy() ) if Tk::Exists($frame); } ) -> pack ( -side => 'top', -fill => 'x',); $self -> Advertise ('entry' => $frame ); $self -> ConfigSpecs ( DEFAULT => [$frame], text => [$label] ## IF ID DONT have the string 'text => [$labe +l]' ); ## then it will choke on '-text => $header_m +sg' ## WHY? $self -> Delegates ( DEFAULT => $frame, bind => $entry, # NOTE ); } ## CLOSE Populate 1; } ## CLOSE package ## Invoke the MEGAWIDGET down here to test ## my $mw = MainWindow -> new; $mw -> geometry('300x300+900+250'); $mw -> title('Main Window '); my $header_msg ="FOOOOO"; my $input = ''; my $dialog = $mw ->DialogBox( -title => ' ', -buttons => []); my $entry = $dialog -> GUIask( -textvariable => \$input, -label => $header_msg )-> pack(); $entry -> bind( '<Return>' , sub # NOTE { print "input = $input\n"; $dialog -> destroy(); } ); $dialog->Show; # NOTE MainLoop;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Building an adaptable 'Entry Widget'
by Anonymous Monk on Feb 21, 2022 at 15:14 UTC | |
by Anonymous Monk on Feb 21, 2022 at 15:21 UTC | |
by choroba (Cardinal) on Feb 21, 2022 at 15:41 UTC | |
by LanX (Saint) on Feb 21, 2022 at 18:13 UTC | |
by Anonymous Monk on Feb 22, 2022 at 02:37 UTC | |
by LanX (Saint) on Feb 22, 2022 at 12:32 UTC | |
by Anonymous Monk on Feb 22, 2022 at 21:23 UTC |