问题描述
我有一个带有按钮图像的Button
,但是当它在我的窗口中时,按钮的背景与窗口的背景发生冲突.它是.png图像,但tkinter
似乎想通过添加灰色空间将图像保持为四边形.有没有一种方法可以使按钮的空白变得透明,以便您只剩下按钮图像?
I have a Button
with a button image but when it is in my window the background of the button clashes with the background of the window. It is a .png image but tkinter
seems to want to keep the image as a quadrilateral by adding grey space. Is there a way to make the empty space of a button become transparent so that you are just left with the button image?
我正在Windows 8上使用Python 3.4.2.
I am using Python 3.4.2 on Windows 8.
推荐答案
如果您将.png与import PIL
一起使用,则python支持透明性.
If you are using a .png with import PIL
python is supporting the transparency.
但是,在tkinter
中,.Button
小部件不支持透明度.
However, within tkinter
the .Button
widget does not support transparency.
因此,您将获得的是纯色背景上的透明图像.
So what you will have is transparent image on top of a solid background.
如果您是Windows用户,那么最好的选择就是以下解决方案:
If you are a windows user, your best bet is this solution:
这篇关于Tkinter中的按钮上的透明背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!