本文介绍了标签上的Tkinter透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

和文件 https://imgur.com/a /JR4Hc

推荐答案

不是Label无法显示透明图像,而是标签具有自己的背景颜色,该背景颜色不透明或与其父级相同.一种解决方法只是将其父级的bg用作其自己的bg:

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']

这篇关于标签上的Tkinter透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 17:48