以下是绝大部分代码:
""" pillow修改透明度在tkinter画布上显示.py """ import time from tkinter import * from PIL import Image,ImageTk def setalpha(rawim,a): pass root = Tk() root.title('pillow修改透明度在tkinter画布上显示by李兴球') cv = Canvas(root,width=480,height=360,bg='white') cv.pack() bg = ImageTk.PhotoImage(file='c:/电影院外面.png') cv.create_image(240,180,image=bg) im = Image.open("c:/cat.gif") im = im.convert('RGBA') img = ImageTk.PhotoImage(im) cat= cv.create_image(240,220,image=img) while 1: b = time.time() for a in range(255,-1,-10): im1 = setalpha(im,a) img = ImageTk.PhotoImage(im1) cv.itemconfig(cat,image=img) cv.update() time.sleep(0.01) print(time.time() - b) b = time.time() for a in range(0,256,10): im1 = setalpha(im,a) img = ImageTk.PhotoImage(im1) cv.itemconfig(cat,image=img) cv.update() time.sleep(0.01) print(time.time() - b)
需要完整代码及素材请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)
发表评论