Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using tk simple ->geometry question 1

Status
Not open for further replies.

NEVERSLEEP

Programmer
Apr 14, 2002
667
CA
hi
i just want to know how to center a tk application
or get the screen width & height
curently i use a geometry method to place it on the screen
Code:
use strict;
require Tk;
use Tk;
my $main = new MainWindow
# ...
$main->geometry('+30+100');
#...
---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
The following should center the main window.
use Tk;
my $main = MainWindow->new();
$main->withdraw(); # Hide window move to center
#...fill $main with widgets...
$main->Popup(); # Default is center of screen
MainLoop();
 
thanks but...not working...
os = win2kpro
perl -v = v5.6.1 built for MSWin32-x86-multi-thread

was
Code:
use strict;
require Tk;
use Tk;

my $main = new MainWindow;
$main->minsize( qw(500 500));
$main->title("the title");
$main->configure(
 -background => 'lightgrey'
);
$main->geometry('+30+100');
# ...

i tried this
Code:
use strict;
require Tk;
use Tk;

my $main = new MainWindow;
$main->withdraw();
$main->minsize( qw(500 500));
$main->title("the title");
$main->configure(
 -background => 'lightgrey'
);
$main->Popup();
# ...

this always opened the tk window at same place but not the center...

im a newbie with tk
help me! thanks ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
Here's another way that I found at http:/perltk.org
Code:
use strict;
require Tk;
use Tk;

my $main = new MainWindow;
$main->minsize( qw(500 500));
$main->title("the title");
$main->configure(-background => 'lightgrey');
CenterWindow($main, 500, 500);

#################################################### 
sub CenterWindow { 
#################################################### 
# Args: (0) window to center 
# (1) [optional] desired width 
# (2) [optional] desired height 
# 
# Returns: *nothing* 
#################################################### 
my($window, $width, $height) = @_; 

$window->idletasks; 
$width = $window->reqwidth unless $width; 
$height = $window->reqheight unless $height; 
my $x = int(($window->screenwidth / 2) - ($width / 2)); 
my $y = int(($window->screenheight / 2) - ($height / 2)); 
$window->geometry($width . "x" . $height . "+" . $x . "+" . $y); 
} 
MainLoop();
 
thanks ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top