如何在tkinter中设置行和列之间的空间

时间:2019-12-22 18:18:56

标签: python python-3.x tkinter grid

如果我有此代码:

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)

如何设置列之间的距离?

1 个答案:

答案 0 :(得分:3)

grid几何管理器有两个选项padxpady,它们允许一个选项定义水平或垂直的额外空间:

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)