For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > January 2005 > Keeping window on top and disabling window closure









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Keeping window on top and disabling window closure
kw

2005-01-13, 8:58 pm

Hi. I'm still fairly new to Perl/Tk and have what shouldn't be first time
questions.

When having a popup menu requesting something crucial, we don't want the
user to ignore it.

I don't necessarily need to do all of the following, but would be curious to
know how to:

- pop the window back to the top after n-seconds if they put another window
over it
- always keep the window on top of other windows (other moved windows will
go under)
- keep the window from being partially moved off the screen
- keep the window in a specific location
- prevent the user from closing the window (until specific information is
provided)
- prevent minimizing/iconizing the window

Thanks.


zentara

2005-01-14, 3:59 pm

On Thu, 13 Jan 2005 18:22:36 -0600, "kw" <s h o c k e r s _ j m @ y a h
o o . c o m> wrote:

>Hi. I'm still fairly new to Perl/Tk and have what shouldn't be first time
>questions.
>
>When having a popup menu requesting something crucial, we don't want the
>user to ignore it.
>
>I don't necessarily need to do all of the following, but would be curious to
>know how to:
>
>- pop the window back to the top after n-seconds if they put another window
>over it
>- always keep the window on top of other windows (other moved windows will
>go under)


#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::DialogBox;

my $mw = MainWindow->new();
$mw->geometry("600x400+100+100");

my $dialog = $mw->DialogBox(
-title => 'Test',
-buttons => [qw/Yes No Cancel/],
);

my $lifter;
$mw->Button(-text=>'Get_dialog',
-command => sub{
$lifter = $mw->repeat(100,sub{ $dialog->raise });
my $answer = $dialog->Show;
$lifter->cancel;
#do your $dialog return testing

}

)->pack;
MainLoop;
__END__


>- keep the window from being partially moved off the screen


Don't know, test for position somehow, and if any position is negative,
move it back to center?

>- keep the window in a specific location


#!/usr/bin/perl
use warnings;
use strict;
use Tk;

my $mw = tkinit;
$mw->geometry("200x300+200+200");

$mw->overrideredirect(1); # set the override-redirect flag

$mw->packPropagate(0); # prevent the window being resized
# for this demo
$mw->Button(
-text => 'Quit',
-command => sub { Tk::exit(0) },
)->pack(
-side => 'bottom',
);

# after a delay:
# withdraw
# clear the override-redirect flag
# re-map the window
$mw->after(
4000,
sub {
$mw->withdraw;
$mw->overrideredirect(0);
$mw->deiconify;
$mw->raise;
}
);

MainLoop;
__END__



>- prevent the user from closing the window (until specific information is
>provided)


#!/usr/bin/perl
use warnings;
use strict;
use Tk;

my $mw = new MainWindow;
$mw->title("Close test");
$mw->geometry("400x250");

#prevents mw from closing
$mw->protocol('WM_DELETE_WINDOW' => sub {});

MainLoop;
__END__


>- prevent minimizing/iconizing the window


Use the
$mw->overrideredirect(1);
again?


>
>Thanks.
>



--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com