Tkinter 窗口中的透明背景和顶部窗口边框 [英] Transparent background and top window border in a Tkinter window

查看:52
本文介绍了Tkinter 窗口中的透明背景和顶部窗口边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试用 png 制作启动画面.我在 macOS 10.14.4 和 Visual Code 1.33.1 下使用 Python 3.7.4 64 位

I try to make a splash screen with a png. I use Python 3.7.4 64-bit, under macOS 10.14.4 and Visual Code 1.33.1

使用 root.overrideredirect(True) 不显示任何窗口.使用 root.overrideredirect(False) 可以正确显示 png,但顶部窗口边框可见.

With root.overrideredirect(True) no windows are displayed. With root.overrideredirect(False) the png is correctly displayed but the top window border is visible.

import tkinter as tk

root = tk.Tk()
# Hide the root window drag bar and close button
root.overrideredirect(True)
# Make the root window always on top
root.wm_attributes('-topmost', True)
# Turn off the window shadow
root.wm_attributes('-transparent', True)
# Set the root window background color to a transparent color
root.config(bg='systemTransparent')

root.geometry('+300+300')

# Store the PhotoImage to prevent early garbage collection
root.image = tk.PhotoImage(file='./local/pics/splash.png')
# Display the image on a label
label = tk.Label(root, image=root.image)
# Set the label background color to a transparent color
label.config(bg='systemTransparent')
label.pack()

root.mainloop()

感谢您的帮助

推荐答案

这将隐藏标题栏

并始终将您的窗口固定在顶部:

and fixates your window to top always:

root.attributes('-type', 'dock')

如果顶部不需要它:

If you don't need it at the top:

root.attributes('-type', 'splash')

这将隐藏标题栏
如果可以改进,请发表评论.

This will hide the title bar
If this can be improved please comment.

这篇关于Tkinter 窗口中的透明背景和顶部窗口边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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