【发布时间】:2021-04-06 18:52:10
【问题描述】:
创建带有图像的按钮时,您可以使用bg='color' 参数将其背景颜色指定为与根背景颜色相同,这样如果您有一个透明背景的图像,结果看起来不错。
但是由于某种原因,当您单击按钮时,只要单击发生,就会有一个白色的闪光覆盖按钮。
我有这个代码:
from tkinter import Tk, Button
from PIL import Image, ImageTk
root = Tk()
root.config(bg='black')
image = Image.open('your_image_file').resize((50, 50))
image = ImageTk.PhotoImage(image)
button = Button(root, width=50, height=50, image=image, bg='black')
button.pack()
root.mainloop()
在导入 PIL(如果还没有的话)然后为您的图像填充适当的路径名后,代码应该可以正常运行
请注意,当您单击图像时,会出现覆盖按钮的白色闪光?
我想摆脱那个
我尝试传递参数 highlightcolor highlightbackground 和 highlightthickness 并使用它们,但无论我是否更改 highlightthickness=0 或 highlightbackground='blue',都没有真正改变
有没有办法正确地做到这一点?
提前致谢!
【问题讨论】:
标签: python tkinter tkinter-button