我找到了这个问题的解决办法。我试图解决一个类似的问题:我想把图像贴上标签。我将图像大小设置为标签大小。当我试图用命令label.config(image=img)放置它时,标签大小会增大。图像的大小是我设置的,所以它没有完全覆盖标签。我在用网格管理器。所有尺寸均未输入“高级”,而是由Tkinter计算。我用的是grid_columnconfigure和grid_rowconfigure。我找到的解决方案是将这个带有图像的标签(或者您的例子中的按钮)设置为LabelFrame,并将grid_propagate设置为False。
代码示例:MyWindow = tk.Tk()
MyWindow.geometry("500x550")
#create LabelFrame (200x200)
label = tk.LabelFrame(MyWindow, width=200, height=200)
#grid manager to set label localization
labelk.grid(row=0, column=0)
#label row and column configure: first argument is col or row id
label.grid_rowconfigure(0, weight=1)
label.grid_columnconfigure(0, weight=1)
#cancel propagation
label.grid_propagate(False)
#Create button and set it localization. You can change it font without changing size of button, but if You se