有什么方法可以在python tkinter中调整按钮大小吗?
我试图使用button.config(width = 100, hight = 100)
来调整python 3.7.2 tkinter中按钮的大小,但是无法正常工作。有什么方法可以调整按钮的大小?
我使用Python 3.7.2和Windows 10。
import tkinter as tk
win = tk.Tk()
#*** Settings ***#
win.title("Project_title")
win.geometry("660x450")
win.resizable(False, False)
wall = tk.PhotoImage(file = "pictures_gui.gif")
wall_label = tk.Label(image = wall)
#*** Settings ***#
#*** Test code ***#
def click_me():
button.configure(text="** I have been clicked")
button = tk.Button(win,text = "Click me!",command=click_me)
button.grid(column=1, row=0)
button.config(width = 100,hight = 100)
#*** Test code ***#
win.mainloop()
答案 0 :(得分:0)
我猜您要设置按钮大小(以像素为单位)。当按钮显示文本但不显示图像时,按钮大小默认为字符。要使大小成为像素,您必须在按钮中显示图像。请参见下面的示例:
currentDay.nextDay()
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()
图像为1x1像素,颜色透明。