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 ); }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re^5: Perl Tk (Kinda urgent) by zentara
in thread Perl Tk (Kinda urgent) 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.