如果我有此代码:
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)
如何设置列之间的距离?
答案 0 :(得分:3)
grid
几何管理器有两个选项padx
和pady
,它们允许一个选项定义水平或垂直的额外空间:
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)