Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_img_putalpha.py
- from Tkinter import *
- from PIL import Image, ImageTk, ImageDraw, ImageChops
- root = Tk()
- root.title("Tk_putalpha")
- root.geometry("500x500")
- wi = 500
- he = 500
- w = Canvas(root, width=wi, height=he)
- w.pack()
- dia = 128
- circle = Image.new("L", (dia * 4, dia * 4), 0)
- dctx = ImageDraw.Draw(circle)
- dctx.ellipse([dia, dia, dia * 3, dia * 3], fill=255)
- del dctx
- offset = dia // 2
- r = ImageChops.offset(circle, offset, offset)
- g = ImageChops.offset(circle, -offset, offset)
- b = ImageChops.offset(circle, 0, -offset+12)
- dimg = Image.merge("RGB", (r, g, b))
- mask = Image.eval(dimg.convert("L"), lambda p: 255 if p > 0 else 0)
- dimg.putalpha(mask)
- #
- imgTk = ImageTk.PhotoImage(dimg)
- w.create_image(0, 0, anchor=NW, image=imgTk)
- root.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement