I am trying to create a translucent window in Tkinter like the one in windows 11
这个怎么做?如果我们不能做到这一点,我们可以捕获屏幕的一部分并使用 cv2 对其进行模糊处理,并将其用作持续更新的背景吗?
不,这不能直接通过tkinter
. But:
如果你使用PIL
,您可以获取窗口的位置,然后进行屏幕截图,然后对其进行模糊处理,然后将其设为您的应用程序背景。但如果用户尝试移动/调整应用程序大小,这将不起作用。但这是一个粗略的代码:
from tkinter import *
from PIL import ImageTk, ImageGrab, ImageFilter # pip install Pillow
root = Tk()
root.overrideredirect(1) # Hide the titlebar etc..
bg = Canvas(root)
bg.pack(fill='both',expand=1)
root.update()
# Get required size and then add pixels to remove title bar and window shadow
left = root.winfo_rootx()
top = root.winfo_rooty()
right = left + root.winfo_width()
bottom = top + root.winfo_height()
root.withdraw() # Hide the window
img = ImageGrab.grab((left,top,right,bottom)) # Get the bg image
root.deiconify() # Show the window
img = img.filter(ImageFilter.GaussianBlur(radius=5)) # Blur it
img = ImageTk.PhotoImage(img)
bg.create_image(0,0, image=img, anchor='nw') # Show in canvas
label = Label(root,text='This is a translucent looking app')
bg.create_window(bg.winfo_width()/2,bg.winfo_height()/2,window=label) # Position in the center
root.mainloop()
输出与tkinter
:
tkinter
如果您想追求现代外观,则不是最佳选择,请使用PyQt
并检查丙烯酸树脂
输出与PyQt
:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)