【发布时间】:2021-07-24 16:48:05
【问题描述】:
在我的 python 程序中,我有一个标题图像,但是它的 png 背景显示为白色。
我的图片代码如下:
from tkinter import *
from typing import final
import requests
from PIL import ImageTk, Image
root = Tk()
# get system display settings
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
path = 'C:/Users/Sam/Desktop/Clash Clan Manager/Graphics Based Program/Game Graphics/'
root.title("Clash Clan Manager")
root.iconbitmap(path + 'CCM logo circle.ico')
root.geometry(str(screen_width) + 'x' + str(screen_height-70))
# display title
titleImage= ImageTk.PhotoImage(Image.open(path + 'clash clan manager text.png'))
titleCanvas= Canvas(root, width= 1374, height= 396)
titleCanvas.pack()
titleCanvas.create_image(10,10,anchor=NW,image=titleImage)
# display background image
background = ImageTk.PhotoImage(Image.open(path + 'background image.png'))
backgroundCanvas = Canvas(root, width=screen_width, height = screen_height-70)
backgroundCanvas.pack()
backgroundCanvas.create_image(10,10, anchor=NW, image =background)
root.mainloop(0)
如何让标题透明化?
【问题讨论】:
-
PNG不允许透明。 -
@Xitiz 你是什么意思 png 是透明的?
-
@SamLeighton 我认为您对 PNG 透明的看法是正确的。
tkinter.Labels 也不允许透明度。尝试改用tkinter.Canvas -
你的PNG透明吗?这不仅仅是“发生”,它必须被标记。格式本身确实支持它,en.wikipedia.org/wiki/…
-
@TheLizzard 你介意向我解释一下画布是如何工作的吗?我有点 tkinter noob