We now have a youtube channel. Subscribe!

Python Tkinter grid() Geometry Manager



Hello dear readers! welcome back to another section of our tutorial on Python. In this tutorial post, we are going to be discussing about the Python Tkinter grid() Method.

Python Tkinter grid() geometry manager arranges widgets in a table-like structure in the parent widget.

Syntax

The following below is the syntax for this method -

widget.grid( grid_options )

Options

Below is the list of possible options -

  • column - The column to put widget in; the default is 0 (leftmost column).
  • columnspan - The number of columns that the widget occupies; default is 1.
  • ipadx, ipady - The number of pixels to pad the widget, horizontally and vertically, inside widget's borders.
  • padx, pady - The number of pixels to pad the widget, horizontally and vertically, outside widget's borders.
  • row - The row to put widget in; the default is the first row that is still empty.
  • rowspan - The number of rows that widget occupies; default is 1.
  • sticky - What to do if the cell is larger than the widget. By default, with sticky, widget is centered in its cell. sticky may be the string concate of zero or more of N, E, S, W, NE, NW, SE and SW compass directions that indicates the sides and corners of the cell to which widget sticks.


Example

Try the following example below -

import Tkinter
root = Tkinter.Tk(  )
for r in range(3):
   for c in range(4):
      Tkinter.Label(root, text='R%s/C%s'%(r,c),
         borderwidth=1 ).grid(row=r,column=c)
root.mainloop(  )

Output

When the above code is executed, it will produce the following result -



Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the Python Tkinter place() Method.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain