-Q10.F.6- create equal sized buttons?

From: -X-  How, in Tk, can I XXX:

A10.F.6. Recently, Micael Salmon <etxmesa@eos.ericsson.se> posted:

In article <1993Jun23.065417.4302@ericsson.se>, I write:
|> I am currently working on yet another tn3270 emulator and I have run
|> into a problem with creating equal sized buttons. I have created an
|> array of buttons for PF and cursor keys and I would now like to make
|> them all the same size. Arranging them into columns was not
|> a problem but when I add bitmaps the buttons lose their horizontal
|> alignment. What I tried was to read the height and width of the buttons
|> using winfo, determine the largest and then use pads to force them to
|> be the same size, this doesn't seem to work. The technique of using
|> pre-set height and width doesn't seem applicable when using a mixture
|> of bitmaps and text as the size in pixels of a text button is font
|> dependent. All suggestions welcome.

Jim Wight <J.K.Wight@newcastle.ac.uk> suggested using reqheight and reqwidth
and then specifying padx and pady in the pack command for each button.
Jim says:
I think it only fair to point out that it was Tuomas J Lukka
<lukka@klaava.Helsinki.FI> who suggested the use of reqwidth and reqheight when I asked how to get over the deficiencies in my first attempt at a solution
that I posted to this group.

Since you're all agog I might as well post the final solution (more or less)
that I mailed to Michael.

frame .frame1
frame .frame2
button .frame1.a -text "pretty long button text"
button .frame1.b -text "short one"
button .frame2.c -bitmap "@/usr/include/X11/bitmaps/xlogo32"
button .frame2.d -text "tiny"

set long [winfo reqwidth .frame1.a]
set short [winfo reqwidth .frame1.b]
set medium [winfo reqwidth .frame2.c]
set tiny [winfo reqwidth .frame2.d]
set pady [expr [winfo reqheight .frame2.c]-[winfo reqheight .frame2.d]]

pack append .frame1 .frame1.a "filly pady $pady"
pack append .frame1 .frame1.b "fillx padx [expr $long-$short] filly pady $pady"pack append .frame2 .frame2.c "fillx padx [expr $long-$medium] filly"
pack append .frame2 .frame2.d "fillx padx [expr $long-$tiny] filly pady $pady"
pack append . .frame1 {left} .frame2 {left}
Go Back Up

Go To Previous

Go To Next