Python Tkinter,透明背景,Linux

Python Tkinter,透明背景,Linux,python,linux,tkinter,Python,Linux,Tkinter,有没有办法在Linux上的Tkinter窗口中获得透明背景 我目前看到的唯一方式是: import tkinter as tk root = tk.Tk() root.overrideredirect(True) root.wait_visibility(True) root.wm_attributes("-alpha", 0.0) canvas = tk.Canvas(root, width=300, height=300) canvas.pack() canvas.create_rec

有没有办法在Linux上的Tkinter窗口中获得透明背景

我目前看到的唯一方式是:

import tkinter as tk

root = tk.Tk()

root.overrideredirect(True)
root.wait_visibility(True)
root.wm_attributes("-alpha", 0.0)

canvas = tk.Canvas(root, width=300, height=300)
canvas.pack()
canvas.create_rectangle(50, 25, 150, 75, fill="red")

root.mainloop()
然而,这不是我想要的。我想让背景是透明的,这样我的覆盖可以是其他东西

我在这里找到了一些帖子,但它们只涉及Windows和Mac操作系统上的bg透明度。与Linux相关的只是alpha

添加此行:

root.wait_visibility(root)
在“root.wm_attributes..”行之前,如中所述
它在Ubuntu 16.04上对我有效,我很确定这会起作用

root.wm_attributes("-alpha", 0.5)
root.wait_visibility(root)

我知道整个窗口上的alpha,但是我只想让bg透明,不知道你的意思。“叠加”是指文本吗?使用上面的代码,如果我添加一个文本小部件,我可以看到其中的文本,而背景保持透明。我改进了这个问题。我不知道文本,但我正在尝试绘制其他具有100%透明背景的对象。您是否尝试过
root.attributes('-transparentcolor',root['bg'])
?不,这只会导致错误:回溯(上次调用):root.wm_attributes('-transparentcolor',root['bg'])文件中的第24行“/bg.py File”“/usr/lib/python3.6/tkinter/_init__.py”,第1782行,在wm_属性中返回self.tk.call(args)_tkinter.TclError:坏属性”-transparentcolor“:必须为-alpha、-topmest、-zomed、-fullscreen或-typeDid才能解决此问题@Drew?Hi@SuspectAverage5。”。谢谢你的回答。通常这里更欢迎有解释的答案。您想更新您的答案以提供简短的解释吗?