When you don't use the Window Manager controls in Tk, the iconify and other methods don't work. So you may need to work out someway to bring the window back after
it has been withdrawn, because there won't be anything in the WindowManager's tray. You may need to control the overrided window from another window, or devise a way to construct your own minimized icon somewhere on the screen. In the meantime, here is a quick hack. It throws a harmless error, but luckily, deiconify works, even though iconify dosn't. UPDATE July 3, 2011 After reading over perldoc Tk::Widget, I see that it is better to use UnmapWindow, and MapWindow, rather than withdraw and deiconify. So better code would be:
-command => sub {
#$top->withdraw;
$top->UnmapWindow;
my $timer = Tk::after(2000,
sub{
#$top->deiconify; # throws a tcl warning
$top->MapWindow;
});
P.S. Gtk2's method of removing window manager controls is better than Tk, as it will still show an overrideredirected window in the Window Manager's tray.
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
my $top = MainWindow->new;
$top->geometry('200x200+200+200');
$top->overrideredirect(1);
$top->Label( -text => 'Click and Drag' )->pack(
-expand => 1,
-fill => 'both'
);
$top->Button(
-text => 'Minimize',
-command => sub { $top->withdraw;
my $timer = Tk::after(2000,
sub{
$top->deiconify;
});
}
)->pack;
$top->Button(
-text => 'Exit',
-command => sub { $top->destroy }
)->pack;
my @deltaxy;
$top->bind( '<1>' => \&getdelta );
$top->bind( '<B1-Motion>' => \&mousemove );
MainLoop;
sub mousemove {
my ( $width, $height, $x, $y ) = split /[+x]/, $top->geometry;
$x = $top->pointerx - $deltaxy[0];
$y = $top->pointery - $deltaxy[1];
$top->geometry( $width . 'x' . $height . "+$x+$y" );
}
sub getdelta {
@deltaxy = ( $top->pointerx - $top->x, $top->pointery - $top->y );
}
|