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;

In reply to Building an adaptable 'Entry Widget' by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.