in reply to Is this megawidget doable

It's my opinion that you are using DialogBox incorrectly by not having any buttons.

If you are always putting GUIask in a DialogBox, I would do it this way. If not, please provide a more extensive sample program.

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11141756 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 ) = @_; $self ->SUPER::Populate($args) ; 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'); $self -> Advertise ('entry' => $frame ); $self -> ConfigSpecs ( DEFAULT => [$frame], textvariable => [$entry], # NOTE text => [$label] ); $self -> Delegates ( DEFAULT => $frame, bind => $entry, ); } ## 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 => [qw(OK Abort) +]); my $entry = $dialog -> GUIask( -textvariable => \$input, -text => $header_msg )-> pack(); my $reply = $dialog->Show; # NOTE $reply eq 'OK' and print "input = $input\n"; MainLoop;

Replies are listed 'Best First'.
Re^2: Is this megawidget doable
by Anonymous Monk on Mar 03, 2022 at 12:43 UTC

    Thanks -- that did what I wanted. I noticed you added the line:

    my $dialog = $mw ->DialogBox( -title => ' ', -buttons => [qw(OK Abort) +]);

    Did this have anything to do with my nutty results? If so , then why?

Re^2: Is this megawidget doable
by Anonymous Monk on Mar 03, 2022 at 12:56 UTC

    OK. So you took the -buttons stuff from the Tk::DialogBox manpage. What if I only want an 'Abort' button that has a red background? Or is that over-complicating the matter?

      If that's what you want, then don't use DialogBox. See Tk::Popup for other choices.