[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Second Try: How to align widgets on the left side in Ruby/Tk?

Ronald Otto Valentin

5/19/2006 6:46:00 AM

I posted the question below some time ago, but did not receive any
comment,
so I will try it a second time. Actually I was surprised that it seems
to be a
much more difficult problem than I first thought. I short, I would like
to align
a bunch of fields in a form, so that each field starts to on the left,
instead of
being centered. In detail, the problem is this:

My window should consists of several "lines". Each line consists of
- a checkbox
- a label
- an entry field

for example (the X denoting a checkbox):

X LABEL1 entry field for user data
X LABEL2 another entry field where the user can enter some value
X LABEL3 a third entry field

I used the following approach (which works basically well - but see
below):

# Code for adding one line to the root window:
frame=TkFrame.new(root)
frame.pack()
check=TkCheckButton.new(frame).pack("side" => "left")
label=TkLabel.new(frame) { text "...." }
label.pack("side" => "left")
entry=TkEntry.new(frame).pack("side" => "left")
entry.value="...."

Now the problem is that since the label texts and initial values
for each line are of different size, and since by default the
frame is centered within the root window, the check buttons
turn out to be not lined up one below the other, which gives
an ugly look, like this:

X LABEL1 entry field for user data
X LABEL2 another entry field where the user can enter some value
X LABEL3 a third entry field

I.e. the fields in the frames are centered instead of being left
justified.

I tried to remedy this by changing the first statement to

frame=TkFrame.new(root) { justify 'left' }

but this does not work, because "justify" is not valid for a TkFrame.

How do I get a left-justified layout?

Ronald

2 Answers

lloyd@binaryten.com

5/19/2006 1:37:00 PM

0

the alignment you suggest sounds very much like a job for 'grid' as
opposed to 'pack'

I am tempted to give you the answer but you will feel much better after
refering to the perl/tk docs which are essentially the same for the
ruby implementation

lloyd@binaryten.com

5/19/2006 1:47:00 PM

0

the alignment you suggest sounds very much like a job for 'grid' as
opposed to 'pack'

I am tempted to give you the answer but you will feel much better after
refering to the perl/tk docs which are essentially the same for the
ruby implementation