如何使用 Tkinter 创建透明小部件? [英] How to create transparent widgets using Tkinter?

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

问题描述

我是 Python 新手.我想创建一个以图像为背景的应用程序.但是当我在图像上添加一个标签"时,我可以看到标签的背景是白色的.我们是否有将标签"小部件颜色设置为透明"的解决方案?

I'm new to Python. I wanted to create an app which has an image as its background. But when I add a 'Label' over the image, I could see a white background to the label. Do we have a solution to make the 'Label' widgets color set to 'transparent' ?

推荐答案

我不知道让标签背景透明的方法.一种替代方法是使用 Canvas 小部件作为整个事情的基础,然后使用 create_image 方法添加背景图像,并使用 create_text 制作文本标签.这将需要更多的工作,但文本应该在图像顶部没有背景的情况下呈现.(诚​​然,我对 Canvas 小部件的经验很少,所以我更多地是从理论而不是经验,但值得一试.)

I'm not aware of a way to make Label backgrounds transparent. One alternative is to use a Canvas widget as the base for the whole thing, then use the create_image method to add the background image, and create_text to make the text labels. It will be a bit more work, but the text should render without a background on top of the image. (Admittedly I have very little experience with the Canvas widget, so I'm speaking more from theory than experience, but it's worth a try.)

如果你没有好的 Tkinter 参考,我强烈推荐 这个由新墨西哥理工学院制作.它也可以作为可下载的PDF使用.

If you don't have a good Tkinter reference, I highly recommend this one made by New Mexico Tech. It's available as a downloadable PDF as well.

这篇关于如何使用 Tkinter 创建透明小部件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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