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!

Position of Windows, Toplevel in Perl/tk

Status
Not open for further replies.

julie25

Programmer
Aug 7, 2003
22
FR
Hie,

I'm working on an interface in perl/tk.
I create many toplevels but I don't find how to force their position in screen.

More precisely I create a mainwindow and then I'd like to place a top level widget in the center of mainwindow... what is the option associated?

If you can help me!

Thanks a lot,

Julie
 
Have a look at the perl/Tk documentation. If on Windows it should already be installed in the Activestate HTML docs or if on *nix then go to the appropriate perl lib dir and then to the Tk dir. All the man pages in POD format are available.

The one you want to look at is the Toplevel manpage since it talks about specifying that the window be used as a container to embed other widgets/windows in. The MainWindow widget accepts ALL the options that the Toplevel does.

An alternative (I think) might be to specify your Mainwindow with a canvas and use that to embed other objects.
 
thank you for the answer,

but I did not find any option with which to place the toplevel widget in screen or in my window.

If someone knows how to do it...

Thanks,

Julie
 
I don't know anything about Tk but try this...

use Tk;

my $main = MainWindow->new;

$button1 - $main->Button(-text => 'Click Me!')->place(-x => 60, -y => 30);

MainLoop;


Duncan
 
I always used the geometry method of the toplevel. You can set it, or call it empty and it'll return its current state. At that point, you can easily parse out the four parts, and based on it, set the geometry of the new toplevel.
Code:
use warnings;
use Tk;

my $info;
my $mw = MainWindow->new;       #create main window
$mw->geometry("640x480+0+0");   #set initial size to 640x480 in the upper-left corner
                                #width x height + pixels right + pixels down
$mw->Button(-text => "How do I look?",
            -command => sub { $info = $mw->geometry; },
           )->pack;
$mw->Label(-textvariable => \$info)->pack;
MainLoop();

----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
I'm going to try with geometry ...

I was looking for a magic option that would have done all!

Thank you,

Julie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top