简体   繁体   中英

Tkinter Grid Layout

So iv'e been experimenting with tkinter's grid, and have run into a brick wall.

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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