【发布时间】:2016-01-23 23:48:04
【问题描述】:
我正在尝试使用 PIL 实现一个具有透明度的按钮并读取具有透明度的 PNG。我已按照我能找到的所有提示进行操作,但按钮仍然显示不透明。
代码如下:
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()
【问题讨论】:
标签: python python-2.7 tkinter png transparency