Perl Tk Grid

F

f1crazed

Hello,

I am new to using tk and perl. What I am trying to do below is just
get the label and text boxes to line up on the left side and top of
the mainwindow. It seems that there is some kind of padding on the
left side and top of the window that won't allow me to put widgets all
the way on the left and top of the window.

Here is the code:

#!/usr/bin/perl -w
use Tk;
use strict;

my $mw = new MainWindow(); # Main Window
$mw->geometry("400x200+500+400");
$mw->title("Learning Grid");

$mw -> Label(-text=> "hello") -> grid(-row=>0, -column=>0, -sticky =>
'w', );
my $txt = $mw-> Text(-width=>20, -height=>1)-> grid(-row=>2, -
column=>0, -sticky => 'w') ;
my $txt2 = $mw-> Text(-width=>20, -height=>1)-> grid(-row=>3, -
column=>0, -sticky => 'w');

MainLoop;

Thanks for any help!
-JD
 
F

f1crazed

You need to define 'weight' for your rows and columns.
See the gridRowconfigure and gridColumnconfigure statements below.

Also, it is a good idea to put your widgets into a frame rather
than directly into the MainWindow.

#!/usr/bin/perl -w
use Tk;
use strict;

my $mw = new MainWindow(); # Main Window
$mw->geometry("400x200+500+400");
$mw->title("Learning Grid");
$mw->gridRowconfigure(4, -weight => 1,);
$mw->gridColumnconfigure(1, -weight => 1,);

$mw -> Label(-text=> "hello") -> grid(-row=>0, -column=>0, -sticky =>
'w', );
my $txt = $mw-> Text(-width=>20, -height=>1)-> grid(-row=>2, -
column=>0, -sticky => 'w') ;
my $txt2 = $mw-> Text(-width=>20, -height=>1)-> grid(-row=>3, -
column=>0, -sticky => 'w');

MainLoop;

Thanks q! That did the trick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top