Tkinter 窗口中的透明背景和顶部窗口边框

编程入门 行业动态 更新时间:2024-10-16 23:23:30
本文介绍了Tkinter 窗口中的透明背景和顶部窗口边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我尝试用 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 07:09:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390672.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:边框   透明   窗口   背景   窗口中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!