繁体   English   中英

圆角 Tkinter / Canvas 上的透明图像 Tkinter

[英]Rounded corners Tkinter / Transparent image on Canvas Tkinter

我正在为程序制作 UI。 I managed to blur the window with a image in a label (see image), i wanted to round the edges of the window, so i created a png image with a corner corner and i'm using self.window.wm_attributes('- transparentcolor','black')使corner.png的黑色透明。

但是给出这个图像

角落在 canvas 上,带有这个脚本

self.img = Image.open('corner.png')
self.canvas = Canvas(self.window, width=50, height=50,bd=0, highlightthickness=0, relief='ridge')
self.canvas.place(x=0,y=20)
self.photoimage = ImageTk.PhotoImage(self.img)
self.canvas.create_image((0,0), image=self.photoimage,anchor='nw')
self.canvas.update() 

我希望能够从 canvas 中删除这个白色背景,我已经尝试将模糊和角落放在同一个 canvas 上,但每次放置角落时,整个背景都会变成白色。

编辑:模糊只是一个截图png,每次点击window时都会更新,opencv GaussianBlur。

Edit2:它正在工作工作

更新:使用此代码,我将角落与模糊放在一起,因此不再需要 canvas output:图片

import cv2 
from pathlib import Path
homeDir = str(Path.home())
path = homeDir + '\Desktop\blur.png'
path2 = homeDir + '\Desktop\corner.png'


from PIL import ImageTk, Image

background = Image.open(path)
foreground = Image.open(path2)

background.paste(foreground, (0, 0), foreground)
background.save(path)

Edit2 上的结果

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM