0
我試圖實現一個使用PIL並閱讀具有透明度的PNG的透明按鈕。我已經遵循了我可以找到的所有提示,但按鈕仍然顯示不透明。 Screenshot of button in GIMPPython 2.7 - 通過PNG文件實現帶有透明度的Tkinter按鈕
下面是代碼:
`
from Tkinter import *
from PIL import Image, ImageTk
root = Tk()
root.resizable(width=FALSE, height = FALSE)
global background, redbutton, rb1
rb1 =ImageTk.PhotoImage(file="test.png")
#confirm the png file is correct format
im = Image.open("test.png")
print im.mode
bg = PhotoImage(file = "background.gif")
GameWin = Canvas(root, bd = 2, height = 600, width = 450)
GameWin.create_image(0,0, image = bg, anchor = NW)
rb = Button(GameWin, bd=0, image=rb1)
# create a window in the canvas for the button
rb_win = GameWin.create_window(10, 10, anchor=NW, window=rb)
GameWin.pack()
root.mainloop()
`