Zac Brown
Zac Brown

Reputation: 6093

Tkinter grid() Manager

I am having a bit of trouble with the Tkinter grid() manager. It is spacing the rows too far apart. I have two entry widgets to place, and I need one almost directly under the other. When I place them both on the same row and column, but change the pady option, it places them directly on top of each other. I know there has to be a way to fix this, never had this problem before.

I am using Python 2.6 on Windows XP.

Upvotes: 1

Views: 1814

Answers (2)

tzot
tzot

Reputation: 96081

Don't place them in the same row and column; place the upper in a row, and the lower in row+1, both in the same column. That does the trick.

Note that the grid manager does not need to have all rows and columns filled with widgets; it ignores empty rows and columns.

Upvotes: 2

jsbueno
jsbueno

Reputation: 110811

Are these the only 2 widgets? Or is there another widget,in another column, that ismore than one row in height? If so, it should add to it the "rowspan" attribute.

If that is not the case, I suggesttaht for this cell alone (aply to it "row3span 2), you add a Tkinter.Frame widget, and within this Frame, you simply add your desired widgets with the "pack" manager.

So, instead of:

entr1.grid(my_window, row=1, column=1)
entr2.grid(my_window, row=1, column=1)

you do:

frame = Tkinter.Frame(my_window)
entr1 = Tkinter.<Whatever-widget>(Frame, ...)
entr1.pack()
entr2 = Tkinter.<Whatever-widget>(Frame, ...)
entr2.pack()

Upvotes: 2

Related Questions