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

perl/tk mainwindow position 2

Status
Not open for further replies.

ryancomps

Programmer
Jan 17, 2003
18
IE
When I open a new mainwindow in perl/tk the position of this new window is randomly selected which doesnt look very professional, especially if its a prompt like "Do you want to save?". Is there an option to specify the screen location of the window (Preferably in the middle of the screen).
Thank You.
 
Check out the geometry method, for example:
Code:
my $mw = MainWindow->new;		#create main window
$mw->geometry("640x480+0+0");		#set initial size to 640x480 in the upper-left corner
Sorry I don't have a link with more detail, I haven't found a good online resource for Perl/Tk yet. ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Code:
#!perl
use strict;
use Tk;
my $message;
my $mw1 = MainWindow->new;
$mw1->configure(-title=>"perl GUI",
                -background=>'light grey');
                
$mw1->geometry('400x200+200+50');
[red]
Code:
#               |   |   |   #               |   |   \    verical placement
#               |   \    horizontal placement
#               |    verical size
#               horizontal size
[/red]
Code:
my $fr1 = $mw1->Frame(  -relief=>'raised',
            -borderwidth=>2,
            -background=>'light grey')  
    ->pack(-side=>'top', -fill=>'x');

$fr1->Label(-textvariable=>\$message)
	->pack(-side=>'left');

$fr1->Button(-text=>'Exit', 
             -command=>sub{exit})  
    ->pack(-side=>'right');
    
$mw1->Label(-text=>'Use this button to pop another window',
            -background=>'light grey')  
    ->pack(-side=>'top', -fill=>'x');

my $fr2 = $mw1->Frame(-relief=>'raised',
            -borderwidth=>2,
            -background=>'light grey')  
    ->pack(-side=>'top');

$fr2->Button(-text=>'Pop another window', 
             -command=>\&new_win )
    ->pack(-side=>'bottom');
MainLoop;
#----------------------------------------------------------
sub new_win
{
$message = "Popped a second window";
my $mw2 = MainWindow->new;
$mw2->configure(-title=>"perl GUI",-background=>'light grey');
$mw2->geometry('100x100+100+100');
$mw2->Button(-text=>'OK', -command=>sub{ $mw2->destroy; $message = 'Closed the Window.'; } )
        ->pack(-side=>'bottom');
}
[code] 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Thank you,
You have saved me alot of surfing on the net.
 
my $main = new MainWindow;
setwindow($main, 500, 500);
MainLoop();

sub CenterWindow {
my($window, $width, $height) = @_;
$window->idletasks;
my $x = int(($window->screenwidth / 2) - ($width / 2));
my $y = int(($window->screenheight / 2) - ($height / 2));
$window->geometry($width . "x" . $height . "+" . $x . "+" . $y);
}

# not reso depended ...
# i asked same ? long ago ..that the answer i got , here :) ---------------------------------------
wmail.jpg


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

Part and Inventory Search

Sponsor

Back
Top