Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tkinter Python透明背景和(非透明)可见形状?_Python_Python 3.x_Tkinter - Fatal编程技术网

Tkinter Python透明背景和(非透明)可见形状?

Tkinter Python透明背景和(非透明)可见形状?,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,我想创建一个不可见的,透明的背景与可见的形状内的窗口。我编写了下面的代码,但是您可以看到对象也是透明的,我如何解决这个问题 #!/usr/bin/env python3 from tkinter import * window = Tk() window.wait_visibility(window) window.wm_attributes('-alpha',0.1) def drag(event): event.widget.place(x=event.x_root, y=e

我想创建一个不可见的,透明的背景与可见的形状内的窗口。我编写了下面的代码,但是您可以看到对象也是透明的,我如何解决这个问题

#!/usr/bin/env python3

from tkinter import *

window = Tk()
window.wait_visibility(window)
window.wm_attributes('-alpha',0.1)


def drag(event):
    event.widget.place(x=event.x_root, y=event.y_root,anchor=CENTER)

card = Canvas(window, width=74, height=97, bg='blue')
card.place(x=300, y=600,anchor=CENTER)
card.bind("<B1-Motion>", drag)

another_card = Canvas(window, width=74, height=97, bg='red')
another_card.place(x=600, y=600,anchor=CENTER)
another_card.bind("<B1-Motion>", drag)

window.mainloop()
#/usr/bin/env蟒蛇3
从tkinter进口*
window=Tk()
视窗。等待视窗(视窗)
wm_属性('-alpha',0.1)
def拖动(事件):
event.widget.place(x=event.x_root,y=event.y_root,anchor=CENTER)
卡片=画布(窗口,宽度=74,高度=97,背景为蓝色)
卡片位置(x=300,y=600,锚定=中心)
卡片绑定(“,拖动)
另一张卡片=画布(窗口,宽度=74,高度=97,背景为红色)
另一个位置(x=600,y=600,锚定=中心)
另一张卡。绑定(“,拖动)
window.mainloop()
换句话说,我不希望我的对象是透明的。我只希望屏幕是透明的。将来我可能会在窗口中添加图片、矩形等。但我希望它们都能以透明的背景显示出来。有什么帮助吗

我的操作系统:Ubuntu

注意:对于所有面临相同问题的人,我将我的库更改为WXPython。它有透明的背景,透明的窗口,不同形状的窗口等,但如果你们能够找到一个解决方案,我将感谢社区。
在UBUNTU中没有找到这个问题的答案。Windows和Mac都有,BR

我有一个解决办法,它在Windows中工作,不确定ubuntu是否使用透明画布

from tkinter import *

window = Tk()
window.lift()
window.wm_attributes("-topmost", True)
window.wm_attributes("-transparentcolor", 'gray')
window.wait_visibility()

canvas = Canvas(window, width=500, height=500)
canvas.pack()
canvas.config(cursor='tcross')
canvas.create_rectangle(0, 0, 500, 500, fill='gray', outline='gray')

def drag(event):
    event.widget.place(x=event.x_root, y=event.y_root,anchor=CENTER)

card = Canvas(window, width=74, height=97, bg='blue')
card.place(x=0, y=0,anchor=CENTER)
card.bind("<B1-Motion>", drag)

another_card = Canvas(window, width=74, height=97, bg='red')
another_card.place(x=600, y=600,anchor=CENTER)
another_card.bind("<B1-Motion>", drag)
window.mainloop()
从tkinter导入*
window=Tk()
窗户电梯
wm_属性(“-top”,True)
wm_属性(“-transparentcolor”,“灰色”)
window.wait_visibility()
画布=画布(窗口,宽度=500,高度=500)
canvas.pack()
canvas.config(cursor='tcross')
画布。创建矩形(0,0,500,500,fill='gray',outline='gray')
def拖动(事件):
event.widget.place(x=event.x_root,y=event.y_root,anchor=CENTER)
卡片=画布(窗口,宽度=74,高度=97,背景为蓝色)
卡片位置(x=0,y=0,锚定=中心)
卡片绑定(“,拖动)
另一张卡片=画布(窗口,宽度=74,高度=97,背景为红色)
另一个位置(x=600,y=600,锚定=中心)
另一张卡。绑定(“,拖动)
window.mainloop()
参考资料:

输出:

你能换另一张卡吗?位置(x=100,y=100,锚定=中心)

稍后调用这个window.wm_属性(“-transparentcolor”,灰色”)

从tkinter导入*
window=Tk()
窗户电梯
wm_属性(“-top”,True)
window.wait_visibility()
画布=画布(窗口,宽度=500,高度=500)
canvas.pack()
canvas.config(cursor='tcross')
画布。创建矩形(0,0,500,500,fill='gray',outline='gray')
def拖动(事件):
event.widget.place(x=event.x_root,y=event.y_root,anchor=CENTER)
卡片=画布(窗口,宽度=74,高度=97,背景为蓝色)
卡片位置(x=0,y=0,锚定=中心)
卡片绑定(“,拖动)
另一张卡片=画布(窗口,宽度=74,高度=97,背景为红色)
另一个位置(x=100,y=100,锚定=中心)
另一张卡。绑定(“,拖动)
wm_属性(“-transparentcolor”,“灰色”)
window.mainloop()

这些有帮助吗?我正在Ubuntu上工作。这些问题并没有显示ubuntu操作系统的解决方案?这对你的小工具有用吗?我根据链接中的答案编辑了问题。我做错什么了吗?因为它不工作对象仍然是透明的?可能遗漏了什么@A121抱歉,我在windows上工作,因此无法验证上一个链接的合法性。我知道,我不能在windows上做这件事,但为了清楚起见,我想说ubuntu没有“透明色”。我知道你的方法可以在ubuntu中使用吗?你能测试我的代码吗?如果你愿意的话,我可以在ubuntu中测试透明色。这个问题是特定于操作系统的。Mac和Windows可能有。但是在ubuntu.tkinter.TclError:坏属性“-transparentcolor”:必须为-alpha、-topmost、-Zomed、-fullscreen或-type
from tkinter import *

window = Tk()
window.lift()
window.wm_attributes("-topmost", True)
window.wait_visibility()

canvas = Canvas(window, width=500, height=500)
canvas.pack()
canvas.config(cursor='tcross')
canvas.create_rectangle(0, 0, 500, 500, fill='gray', outline='gray')

def drag(event):
    event.widget.place(x=event.x_root, y=event.y_root,anchor=CENTER)

card = Canvas(window, width=74, height=97, bg='blue')
card.place(x=0, y=0,anchor=CENTER)
card.bind("<B1-Motion>", drag)

another_card = Canvas(window, width=74, height=97, bg='red')
another_card.place(x=100, y=100,anchor=CENTER)
another_card.bind("<B1-Motion>", drag)
window.wm_attributes("-transparentcolor", 'gray')
window.mainloop()