Tkinter transparency on label

青春壹個敷衍的年華 提交于 2019-12-18 08:54:44

问题


from tkinter import *

master = Tk()
master.resizable(False, False)
master.geometry('430x480+50+50')
master.title("Ping Check")
master.config(bg="#222")

layer = PhotoImage(file ="logo.gif")
topFrame = Label(text="Ping Checker", image=layer, fg="#fff", font="Bahnschrift 14")
topFrame.place(x=11,y=10)

I'm using the following code, which displays the image, however, the label seems to have a background, which I do not want.

and the file https://imgur.com/a/JR4Hc


回答1:


It's not that the Label can't show a transparent image, it's rather label has its own background color which is not transparent or the same as its parent. One workaround would simply be using its parent's bg as its own bg:

topFrame['bg'] = topFrame.master['bg']


来源:https://stackoverflow.com/questions/48814937/tkinter-transparency-on-label

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!