Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_almond_shapist.py
- import tkinter as tk
- from PIL import Image, ImageDraw, ImageTk
- W = 100
- H = 100
- def update(val):
- y = int(val)
- im = Image.new("L", (W, H), 255)
- d = ImageDraw.Draw(im)
- top = half.crop((0, 0, W, H//2-y))
- im.paste(top, (0, 0))
- bottom = top.transpose(Image.FLIP_TOP_BOTTOM)
- im.paste(bottom, (0, H//2-y))
- tkimg = ImageTk.PhotoImage(im)
- label.config(image=tkimg)
- label.image = tkimg
- root = tk.Tk()
- root.title("tk_almond_shape.py")
- half = Image.new("L", (W, H), 255)
- d = ImageDraw.Draw(half)
- d.pieslice((-50, 0, W*1.5, W*1.5), 180, 360, fill=0)
- im0 = Image.new("L", (W, H), 255)
- tkimg0 = ImageTk.PhotoImage(im0)
- label = tk.Label(root, image=tkimg0, bg='white')
- label.pack()
- slider = tk.Scale(root, from_=0, to=100, orient="horizontal", command=update)
- slider.pack(fill="x")
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment