Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
This is as far as I can get. Why is it I can get LabEntry to return the entered-string, but I cant do so with my widget? I am trying to modify LabEntry because I use this block-of-code/widget a lot. It also needs an ABORT/QUIT button so the user can back-out/cancel.
#!/usr/pkg/bin/perl use strict; use warnings; use diagnostics; 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 names +pace sub ClassInit ## Called once to intitalise new class { my ($class , $mw ) = @_; $class ->SUPER::ClassInit($mw); } sub Populate { my ($self , $args ) = @_; $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() -> pack(-fill => 'x'); my $button = $frame -> Button ( -background => 'Red', -text => "Abort", -command => sub { ($frame -> destroy() ) if Tk::Exi +sts($frame); } ) -> pack ( -side => 'top', -fill => 'x', ); $self -> Advertise ('entry' => $frame ); $self -> ConfigSpecs ( DEFAULT => [$frame], text => [$label] ## IF ID DONT have the string ' +text => [$label]' ); ## then it will choke on '-text + => $header_msg' ## WHY? $self -> Delegates ( DEFAULT => $frame ); } ## CLOSE Populate 1; } ## CLOSE package ######################################################### ######################################################### ## Invoke the MEGAWIDGET down here to test ## my $mw = MainWindow -> new; $mw -> geometry('+900+250'); $mw -> title(' '); my $header_msg ="FOOOOO"; my $input; my $dialog = $mw ->DialogBox( -title => ' ', -buttons => [] ); my $entry = $dialog -> GUIask( # -text => $header_msg, -textvariable => \$input, -label => $header_msg #-label => "FOOOO" )-> pack(); $dialog -> bind( <'KeyPress-Return'> , sub { print "\$input =: $input\n + "; # my $text = $entry -> get(); $dialog -> destroy(); } ); MainLoop;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Building an adaptable 'Entry Widget'
by tybalt89 (Monsignor) on Feb 21, 2022 at 02:03 UTC | |
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 | |
|
Re: Building an adaptable 'Entry Widget'
by choroba (Cardinal) on Feb 20, 2022 at 22:23 UTC |