Description: | This function centers a Tk::Toplevel on the screen, taking into account the window's width and height. Caveat: To get the correct window size, the function has to force the window to update, which causes the window to be displayed if it wasn't. If you want the window to end hidden, leave out the deiconify, near the end. |
sub center { my $win = shift; $win->withdraw; # Hide the window while we move it about $win->update; # Make sure width and height are current # Center window my $xpos = int(($win->screenwidth - $win->width ) / 2); my $ypos = int(($win->screenheight - $win->height) / 2); $win->geometry("+$xpos+$ypos"); $win->deiconify; # Show the window again }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Center a Tk window on the screen
by zentara (Archbishop) on Jan 04, 2003 at 15:32 UTC | |
by bbfu (Curate) on Jan 04, 2003 at 20:03 UTC | |
by zentara (Archbishop) on Jan 05, 2003 at 15:48 UTC | |
Re: Center a Tk window on the screen
by {NULE} (Hermit) on Jan 04, 2003 at 15:05 UTC | |
by bbfu (Curate) on Jan 04, 2003 at 20:02 UTC | |
by {NULE} (Hermit) on Jan 04, 2003 at 22:45 UTC |