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

R

Ronny

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
 
L

lloyd

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
 
L

lloyd

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
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top