Tkinter and the re/sizing of columns in a grid

Discussion in 'Python' started by noman@cyclops.org, Nov 12, 2005.

  1. Guest

    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 12, 2005
    #1
    1. Advertising

  2. Guest

    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-----
     
    , Nov 12, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MISS CHIEVOUS
    Replies:
    51
    Views:
    2,129
    MISS CHIEVOUS
    Apr 19, 2009
  2. random joe
    Replies:
    2
    Views:
    1,103
    eb303
    Jun 14, 2010
  3. Mad Scientist Jr

    problem sizing columns in datagrid

    Mad Scientist Jr, Aug 13, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    169
    Mike Hutton
    Aug 24, 2004
  4. Keefe Goldfisher via .NET 247

    Sizing text entry boxes on in-place editing of datagrid row with dynamically created columns

    Keefe Goldfisher via .NET 247, Mar 7, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    195
    Keefe Goldfisher via .NET 247
    Mar 7, 2005
  5. Eagle

    Sizing of DropDownLists and textboxes in a grid

    Eagle, May 11, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    140
    Eagle
    May 11, 2005
Loading...

Share This Page