我猜你想设置按钮的像素大小。当按钮显示文本但不显示图像时,按钮大小默认为字符。要使大小成为像素,您必须在按钮中显示图像。请参见下面的示例:
import tkinter as tk
win = tk.Tk()
win.geometry("660x450")
win.resizable(False, False)
def click_me():
button.configure(text="** I have been clicked")
# Create a transparent image to allow Button size in pixels
pixel = tk.PhotoImage(file='images/pixel.png')
button = tk.Button(win, text="Click me!", command=click_me,
image=pixel, compound='center')
button.grid(column=1, row=0)
button.config(width=100, height=100) # Config size in pixels
win.mainloop()
这个
pixel.png
图像为1x1像素,颜色透明。