amboxer21 has asked for the wisdom of the Perl Monks concerning the following question:

How would I make a top level window unclosable until a defined action is performed. For example, if I have a password prompt, how would I expand the TLW, remove the close, maximize and minimize icons? And make sure nothing else can be done until the password is entered. I am using Perl Tk
  • Comment on Make top level window unclosable Perl tk

Replies are listed 'Best First'.
Re: Make top level window unclosable Perl tk
by choroba (Cardinal) on Jan 21, 2014 at 23:14 UTC
    You can use
    $toplevel->protocol('WM_DELETE_WINDOW', sub{});

    to disable the close button.

    Update: sub{} used instead of q() after trying myself, even if the documentation states otherwise.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Your suggested code did not work
      $toplevel->protocol('WM_DELETE_WINDOW', q());

      but this did
      $mw->protocol(WM_DELETE_WINDOW => sub { $mw->raise } );

      I appreciate the reply and help!! The MW can still be pushed to the background.
        Yeah, check the update.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Make top level window unclosable Perl tk
by zentara (Cardinal) on Jan 22, 2014 at 15:41 UTC
    how would I expand the TLW, remove the close, maximize and minimize icons? And make sure nothing else can be done until the password is entered. I am using Perl Tk

    You are looking for overrideredirect. In Tk overrideredirect does 2 things, it grabs all virtual desktops and removes Window Manager controls.

    UPDATE: I just noticed an odd behavior with this script. With overrideredirect enabled, I can't get focus to the password entry widgets. Maybe you can fix it. :-)

    #!/usr/bin/perl -w use warnings; use strict; use Tk; use Tk::LabEntry; my $mw = MainWindow->new; my $vh = $mw->vrootheight; my $vw = $mw->vrootwidth; # this is what grabs all virtual desktops # and removes WM controls $mw->overrideredirect(1); # Note that the 'virtual window' height and width are $vh and $vw # respectively, so we use those dimensions for our Canvas height # and width, and let the Canvas expand and fill in both x and y # directions. # my $canvas = $mw->Canvas( -width => $vw, -height => $vh, -background =>'blue', #-takefocus =>0 ); # so canvas dosn't take focus on tab press $canvas->pack(-expand => 1, -fill => 'both'); #just for fun instead of an image $canvas->createRectangle(100, 100, 150, 150, -fill => 'orange'); my %window; my $ypos = 0; foreach ('First', 'Last'){ $window{$_}{'obj'} = $canvas->LabEntry(-label=> $_); $window{$_}{'obj'}->Subwidget('entry')->configure( -background=>'yellow', -textvariable => \$window{$_}{'data'}, ); $window{$_}{'obj'}->configure(-labelPack=>[-side=>'left']); $canvas->createWindow($vw/2, $vh/2 + $ypos, -window=> $window{$_}{'obj'}); $ypos += 40; } $window{'Ok'}{'obj'} = $canvas->Button(-text=> 'Ok', -command=> sub{ foreach ('First', 'Last'){ print "$_ , $window{$_}{'data'}\n"; + } exit; } ); $canvas->createWindow($vw/2, $vh/2 + $ypos + 50, -window=> $window{'Ok'}{'obj'}); $window{'First'}{'obj'}->focus; # this is what grabs all virtual desktops #$mw->overrideredirect(1); MainLoop;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Make top level window unclosable Perl tk (dialog)
by Anonymous Monk on Jan 21, 2014 at 22:47 UTC
    use a dialog, Tk::Dialog, its what you use for password prompts, after you Show it, all other Tk windows are blocked because the dialog is "modal"
Re: Make top level window unclosable Perl tk
by kcott (Archbishop) on Jan 22, 2014 at 15:39 UTC