Tkinter and the re/sizing of columns in a grid

jepler at unpythonic.net jepler at unpythonic.net
Sat Nov 12 14:49:02 EST 2005


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()
#-----------------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20051112/df224aa2/attachment.sig>


More information about the Python-list mailing list