The Grid geometry manager puts the widgets in a 2-dimensional table. The master widget is split into a number of rows and columns, and each “cell” in the resulting table can hold a widget.
The grid manager is the most flexible of the geometry managers in Tkinter. If you don’t want to learn how and when to use all three managers, you should at least make sure to learn this one.
Consider the following example –
Creating this layout using the pack manager is possible, but it takes a number of extra frame widgets, and a lot of work to make things look good. If you use the grid manager instead, you only need one call per widget to get everything laid out properly.
Using the grid manager is easy. Just create the widgets, and use the grid method to tell the manager in which row and column to place them. You don’t have to specify the size of the grid beforehand; the manager automatically determines that from the widgets in it.
Code #2: Creating the layout which is shown above.
Warning: Never mix grid() and pack() in the same master window.
- Python | after method in Tkinter
- minsize() method in Tkinter | Python
- Python | pack() method in Tkinter
- destroy() method in Tkinter | Python
- Python | place() method in Tkinter
- iconphoto() method in Tkinter | Python
- resizable() method in Tkinter | Python
- maxsize() method in Tkinter | Python
- Python | geometry method in Tkinter
- Python Tkinter | grid_location() and grid_size() method
- Python | forget_pack() and forget_grid() method in Tkinter
- Python Tkinter | Moving objects using Canvas.move() method
- Python GUI - tkinter
- Different messages in Tkinter | Python
- RadioButton in Tkinter | Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.