Vimo Vimo - 2 months ago 15
Python Question

How to add space between two widgets placed in grid in tkinter ~ python?

a. Have placed a widget in the row 0 in the grid as shown below.

self.a_button = Button(root, text="A Button")
self.a_button.grid(row=0, column=1)


b. And tried placing another widget in row 2 inside the grid.

self.b_button = Button(root, text="B Button")
self.b_button.grid(row=2, column=1)


But when I run the program, I don't see any space between the widgets, rather its stacked once after the other.

So, how do I program to allow space between two widgets placed in different rows? Share your comments !!

Answer

When you pack the widget you can use

self.a_button = Button(root, text="A Button") 
self.a_button.grid(row=0, column=1, padx=10, pady=10)

Using padx and pady you can add padding to the outer side of the button and alternatively if you want to increase the size of the button you can add inner padding using ipadx and ipady.

If you want more on the Grid function you can view all the options and uses here: http://effbot.org/tkinterbook/grid.htm

Comments