首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tkinter透明背景与(不透明)可见形状?

Tkinter透明背景与(不透明)可见形状?
EN

Stack Overflow用户
提问于 2020-11-28 16:11:15
回答 2查看 791关注 0票数 4

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

代码语言:javascript
复制
#!/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()

换句话说,我不希望我的对象是透明的。我只希望屏幕是透明的。将来,我可能会在窗口中添加图片、矩形等。但我希望他们都能看到透明的背景。有什么帮助吗?

My OS: Ubuntu

注意:对于所有面临同样问题的人,我把我的库改为了WXPython。它有透明的背景,透明的窗口,不同形状的窗户等。但是如果你们能找到解决办法,我将非常感谢社会。在UBUNTU没有找到这个问题的答案。Windows和Mac拥有它,BR

EN

Stack Overflow用户

发布于 2020-12-04 14:38:51

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

代码语言:javascript
复制
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()

参考资料:https://stackoverflow.com/a/42880450/10849457

输出:

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65051696

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档