Python 使用png文件使Tkinter按钮透明

Python 使用png文件使Tkinter按钮透明,python,tkinter,Python,Tkinter,我试图用带有Tkinter的png文件制作一个透明按钮,但我做不到。我也试着用画布或标签来做。我需要一种加载png图像的方法,比如箭头,并在按下它时执行一些操作。 这是我的代码: from Tkinter import * import cv2 import Image, ImageTk class AppButton(Label): def __init__(self,father,imagename): Label.__init__(self,father,width=button

我试图用带有Tkinter的png文件制作一个透明按钮,但我做不到。我也试着用画布或标签来做。我需要一种加载png图像的方法,比如箭头,并在按下它时执行一些操作。 这是我的代码:

from Tkinter import *
import cv2
import Image, ImageTk
class AppButton(Label):

def __init__(self,father,imagename):
    Label.__init__(self,father,width=buttonwidth,height=buttonheight,bd=0)

    orig = Image.open(imagename)
    resized = orig.resize((buttonwidth,buttonheight),Image.ANTIALIAS)
    self.imagetkicon = ImageTk.PhotoImage(resized)
    self.config(image=self.imagetkicon)
    self.bind('<Button-1>',callbackmethod)
从Tkinter导入*
进口cv2
导入图像
类AppButton(标签):
定义初始(自我、父亲、图像名称):
标签。\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
orig=Image.open(imagename)
resized=初始调整大小((按钮宽度,按钮右侧),Image.ANTIALIAS)
self.imagetkicon=ImageTk.PhotoImage(调整大小)
self.config(image=self.imagetkicon)
self.bind(“”,callbackmethod)

谢谢

你说你不能是什么意思?有错误吗?不管怎么说,我认为在Tkinter中并没有透明度。当你们想要一个按钮时,为什么你们要从标签中派生出来?您计划如何测试透明度?(上面的代码不起作用。)我想在标签/按钮上放置一个没有背景色的标签或按钮。我试着用标签,因为我不想要按钮效果。