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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl TK (Centering Windows)

Status
Not open for further replies.

clueo8

Programmer
Jun 13, 2005
47
US
Code:
# Create Main window
my $window = MainWindow -> new();
$window -> minsize(qw(450 250));
$window -> title (" Perl Conversion Tool");
$window -> configure (-background => 'grey');
$window -> geometry('+280+150');

The geometry tag sets the position of the window on the screen. Is there a way to automatically center the window on the screen (so it will be centered on all resolutions)?
 
Try it:


#!/usr/local/bin/perl
use Tk;

my $mw1 = MainWindow->new;
$mw1->configure(-title=>'What is this?');
$mw1->geometry('0x0+0+0');
CenterWindow($mw1);
MainLoop;


#------------------------------------------------------------------------------
# CenterWindow
#------------------------------------------------------------------------------
sub CenterWindow
{
my($window) = @_;
$window->idletasks;
my $width = $window->screenwidth;
my $height = $window->screenheight;
$window->geometry($width . "x" . $height . "+" . 0 . "+" . 0);
}


dmazzini
GSM System and Telecomm Consultant

 
Hellooooooooooo!

It took me some time...but here I came up with it:

#!/usr/local/bin/perl
use Tk;

my $mw = MainWindow -> new ( -title => "MY WINDOW" ) ;
my $width = 300;
my $height = 200;
my $xpos = int(($mw->winfo('screenwidth')-$width)/2);
my $ypos = int(($mw->winfo('screenheight')-$height)/2);
$mw->wm(geometry => "$width"."x$height+$xpos+$ypos");

MainLoop;

dmazzini
GSM System and Telecomm Consultant

 
Thank you very much, this seemed to have done the job!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top