使用png-fi使Tkinter按钮透明

2024-10-04 11:32:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着用一个png文件和Tkinter来制作一个透明的按钮,但是我做不到,我还试着用画布或标签来做。我需要一种加载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)

谢谢!在


Tags: imageimportselfpnginittkinterlabelorig