如何在tkinter中设置行与列之间的间隔

问题描述 投票:2回答:1

如果我有此代码:

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)

如何设置列之间的距离?

python python-3.x tkinter grid
1个回答
0
投票

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)
© www.soinside.com 2019 - 2024. All rights reserved.