如何使 tkinter 标签背景透明? [英] How to make a tkinter Label background transparent?

查看:416
本文介绍了如何使 tkinter 标签背景透明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有标签的窗口作为我的框架.我这样做是因为我想要一个背景图像.但是现在我在使用其他标签时遇到了麻烦.我用来实际标记事物的其他标签没有透明背景.有没有办法让这些标签的背景透明?

I have a window with a label as my frame. I did this because i wanted an image in the background. But now im having trouble with the other labels i have used. The other labels i have used to actually labeled things dont have a transparent background. Is there a way to make the background of these labels transparent?

import Tkinter as tk

root = tk.Tk()
root.title('background image')

image1 = Tk.PhotoImage(file='image_name.gif')

# get the image size
w = image1.width()
h = image1.height()

# make the root window the size of the image
root.geometry("%dx%d" % (w, h))

# root has no image argument, so use a label as a panel
panel1 = tk.Label(root, image=image1)
panel1.pack(side='top', fill='both', expand='yes')

# put a button/label on the image panel to test it
label1 = tk.Label(panel1, text='here i am')
label1.pack(side=Top)

button2 = tk.Button(panel1, text='button2')
button2.pack(side='top')

# start the event loop
root.mainloop()

推荐答案

在 Tk 中不支持透明背景.

It is not supported with transparent backgrounds in Tk.

这篇关于如何使 tkinter 标签背景透明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆