简体   繁体   English

Tkinter网格布局

[英]Tkinter Grid Layout

So iv'e been experimenting with tkinter's grid, and have run into a brick wall. 因此我一直在尝试使用tkinter的网格,并且碰到了砖墙。

So basically i'm trying to create a grid in which I can place multiple elements in like images, buttons, etc. So iv'e been able to understand how to get the buttons placed within frames using row/columns. 因此,基本上,我正在尝试创建一个网格,在其中可以将多个元素放置在图像,按钮等中。因此,我能够理解如何使用行/列将按钮放置在框架中。 But when I specify that I want my first button to be in column 0 and row 0 it'll go to top left but if i specifiy column 2 row 0 rather than leaving a gap and placing it in the second column it'll just put the button right next to the first one. 但是,当我指定我希望第一个按钮位于第0列和第0行时,它将位于左上方,但是如果我指定第2列的第0行而不是留有间隔并将其放置在第二列中,则将其放到第二列第一个旁边的按钮。

So this is an example of what my problem is and what i'm trying to achieve. 因此,这是我的问题所在以及我要实现的目标的示例。

I want B1 to be Column = 0, Row = 0
I want B2 to be Column = 2, Row = 0
I want B3 to be Column = 3, Row = 4

What i'm Getting:                     
-------------
|  B1 |  B2 |
|-----  ----|
|  B3 |     |
------------- 

What I want:
------------------------
| B1 |    | B2 |       |
|-----    ------       |
|                      |
|                      |
|                      |
|                 -----|
|                 | B3 |
|                 -----|
------------------------

Could someone please tell me how i can achieve this. 有人可以告诉我我如何实现这一目标。 I am using python 2.7.11. 我正在使用python 2.7.11。

And another questions apart from that is that I also want to know how i can place an image which is generally larger then a button to fit inside the grid but maintain the positions of the buttons and not break the grid. 除此之外的另一个问题是,我还想知道如何放置通常比按钮大的图像以适合网格内部,但要保持按钮的位置而不破坏网格。

Thanks, and sorry in advance if my questions is to simple or hard to understand what i'm trying to ask for. 谢谢,如果我的问题是简单或难以理解我要问的问题,请提前抱歉。

If a column is empty, it's width will be zero. 如果列为空,则其宽度将为零。 If a row is empty it's height will be zero. 如果一行为空,则其高度将为零。 If you want gaps, you'll need to either explicitly give the row or column a minimum size, or put an in visible element in it. 如果需要间隙,则需要显式为行或列指定最小尺寸,或在其中添加可见元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM