Below is the code to a pTk megapwidget I have been working on. It displays the way I want -- Here is the problem: If I hit <RET> everything goes away (desired result). If I press 'Abort' , the pTk frame and its content go away, but I am left with an mwm-frame with a blank grey background (unwanted). Am I asking pTk to do too much? Is there, then, a better way to do this? Since I seem to rewrite this block of code so much , I want to make as much of this into a reuseable megawidget as possible. Its also a reason for the $header_msg which is customiseable.

#!/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 s +tring 'text => [$label]' ); ## then it will choke on + '-text => $header_msg' ## 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( '<KeyPress-Return>' , sub # NOTE { print "input = $input\n"; $dialog -> destroy(); } ); $dialog->Show; # NOTE MainLoop;

In reply to Is this megawidget doable 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.