473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Tkinter and the re/sizing of columns in a grid


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

--
A strong smell of turpentine prevails throughout.
-- Dr. Oliver Wendell Holmes
Nov 22 '05 #1
1 2083
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)

iD8DBQFDdkcuJd01MZaTXX0RAttPAJsEzGFoWyDnK5HkvMg7JW 0FGK7I2gCfWFLq
zIg/aIfmtayOA3kD9xVQiDc=
=RIEO
-----END PGP SIGNATURE-----

Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Josh | last post by:
Caution, newbie approaching... I'm trying to come up with a very simple Tkinter test application that consists of a window with a drop-down menu bar at the top and a grid of colored rectangles...
2
by: Maboroshi | last post by:
Why when I use the sticky command with the grid layout manager won't my Listbox expand it stays in the center maybe I am missing something but from every tutorial I see it says to do it this way ...
3
by: Brian Mitchell | last post by:
I hate to ask this question because I'm sure it's been asked before, but how do you automatically resize the columns in a datagrid when the form is resized? Thanks!!
4
by: D | last post by:
I'm sure this is a simple question to the Tkinter experts - I have a very basic Tkinter application that consists of 1 master window and buttons within that window. My problem is that, I need to...
3
TMS
by: TMS | last post by:
Only a few weeks of school left. This assignment and then a project to go (GASP). I'm writing a spreadsheet. I am required to have each 'cell' do 2 things: Evaluate if it is an equation, or...
6
TMS
by: TMS | last post by:
This spreadsheet is almost done, but there is some functionality that is driving me nuts. For instance: a cell, for instance 'a0' is to have 'a0' as a string, but if something is entered like...
4
by: beginner | last post by:
Hi All, I am really new to Tk and Tkinter. I googled the web but it was not mentioned how to build a data grid with Tkinter. Basically, I want to show an excel like data grid with fixed column...
2
by: skanemupp | last post by:
so my little calculator works perfectly now. just having some trouble with the layout. this whole tkinter-thing seems to be more tricky than it should be. how can i make the 4 column of buttons...
1
by: Francesco Bochicchio | last post by:
Il Mon, 18 Aug 2008 12:15:10 +0100, dudeja.rajat ha scritto: Uhm, I don't think you should use the grid manager to obtain a window like that. The grid manager is for equally distributing...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.