Tkinter and the re/sizing of columns in a grid

N

noman

I'm using grid() to lay out a column of Labels and a column of Entries
in a frame. If the user changes an Entry so that it's bigger than its
allotted space, i'd like to widen that column to show the entire
string. I've tried <parentFrame>.columnconfigure(1, minsize=newSize),
but that doesn't change anything. I'm obviously missing something. How
should i go about this?

More generally, can anyone point me to info on how to do calculated
sizing and resizing of grids?

thanks,
Eric
 
J

jepler

Normally, an entry widget requests horizontal space equal to the value of the
width= option times the "average" character width of the font it displays.

Setting it to 0 makes the entry request exactly enough width to show the string
it contains.

Making them sticky to the east and west sides of their areas make them grow
to the size of the grid cell, if it is larger than their requested size.

Making the grid column have nonzero weight means that if the user resizes
the window to be wider, extra space will be given to the entry widgets.

Perhaps this program does what you're looking for:
#-----------------------------------------------------------------------
from Tkinter import *

t = Tk()
l1 = Label(t, text="String 1:")
l2 = Label(t, text="String 2:")
e1 = Entry(t, width=0); e1.insert("end", "eggs"); e1.focus()
e2 = Entry(t, width=0); e2.insert("end", "spam")

l1.grid(row=0, column=0, sticky="w")
l2.grid(row=1, column=0, sticky="w")
e1.grid(row=0, column=1, sticky="ew")
e2.grid(row=1, column=1, sticky="ew")

t.grid_columnconfigure(1, weight=1, minsize=120)
t.wm_title("entry width demo")
t.mainloop()
#-----------------------------------------------------------------------

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDdkcuJd01MZaTXX0RAttPAJsEzGFoWyDnK5HkvMg7JW0FGK7I2gCfWFLq
zIg/aIfmtayOA3kD9xVQiDc=
=RIEO
-----END PGP SIGNATURE-----
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top