Matthijs990
Matthijs990

Reputation: 629

How to set the space between rows and columns in tkinter

If I have this code:

from tkinter import *
root = Tk()
def func1():
    print("pressed button 1")
button1 = Button(root,text="button 1",command=func1)
button1.grid(row=0,column=0)
def func2():
    print("pressed button 2")
button2 = Button(root,text="button 2",command=func2)
button2.grid(row=0,column=1)

def func3():
    print("pressed button 3")
button3 = Button(root,text="button 3",command=func3)
button3.grid(row=1,column=0)

how can I set the distance between a row of column?

Upvotes: 0

Views: 210

Answers (1)

sciroccorics
sciroccorics

Reputation: 2427

The grid geometry manager has two options padx and pady that allows one to define extraspace, either horizontally or vertically:

from tkinter import *
root = Tk()
def func1():
    print("pressed button 1")
button1 = Button(root,text="button 1",command=func1)
button1.grid(row=0,column=0,padx=5,pady=5)
def func2():
    print("pressed button 2")
button2 = Button(root,text="button 2",command=func2)
button2.grid(row=0,column=1,padx=5,pady=5)

def func3():
    print("pressed button 3")
button3 = Button(root,text="button 3",command=func3)
button3.grid(row=1,column=0,padx=5,pady=5)

Upvotes: 2

Related Questions