开发者

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 Wi开发者_运维技巧ndows XP.


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.


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()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜