Image 如何使用画布在tkinter中创建透明背景?

Image 如何使用画布在tkinter中创建透明背景?,image,canvas,tkinter,transparent,Image,Canvas,Tkinter,Transparent,我需要照片的背景是透明的;下面是我的代码: from tkinter import * from PIL import ImageTk,Image root=Tk() root.geometry("300x300") root.configure(bg="yellow") image=Image.open("zombie.png") image=image.resize((50,50)) img=ImageTk.PhotoImage(image) canvas=Canvas(width=150

我需要照片的背景是透明的;下面是我的代码:

from tkinter import *
from PIL import ImageTk,Image
root=Tk()
root.geometry("300x300")
root.configure(bg="yellow")
image=Image.open("zombie.png")
image=image.resize((50,50))
img=ImageTk.PhotoImage(image)

canvas=Canvas(width=150, height=100,borderwidth=3,bd=0)
canvas.create_image(50,50,image=img)
canvas.pack()
root.mainloop()

您可以找到有关制作透明背景的更详细说明的更多信息。这可能是一个起点。

这是否回答了您的问题?tkinter画布不能具有透明背景。你能用画布作为背景(而不是
root
)并在其上放置透明的PNG图像吗?链接中说设置
bg=''
将引发错误。