here2share

# tk_almond_shapist.py

Dec 28th, 2025 (edited)
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. # tk_almond_shapist.py
  2.  
  3. import tkinter as tk
  4. from PIL import Image, ImageDraw, ImageTk
  5.  
  6. W = 100
  7. H = 100
  8.  
  9. def update(val):
  10.     y = int(val)
  11.  
  12.     im = Image.new("L", (W, H), 255)
  13.  
  14.     d = ImageDraw.Draw(im)
  15.  
  16.     top = half.crop((0, 0, W, H//2-y))
  17.     im.paste(top, (0, 0))
  18.  
  19.     bottom = top.transpose(Image.FLIP_TOP_BOTTOM)
  20.     im.paste(bottom, (0, H//2-y))
  21.  
  22.     tkimg = ImageTk.PhotoImage(im)
  23.     label.config(image=tkimg)
  24.     label.image = tkimg
  25.  
  26. root = tk.Tk()
  27. root.title("tk_almond_shape.py")
  28.  
  29. half = Image.new("L", (W, H), 255)
  30. d = ImageDraw.Draw(half)
  31. d.pieslice((-50, 0, W*1.5, W*1.5), 180, 360, fill=0)
  32.  
  33. im0 = Image.new("L", (W, H), 255)
  34. tkimg0 = ImageTk.PhotoImage(im0)
  35. label = tk.Label(root, image=tkimg0, bg='white')
  36. label.pack()
  37.  
  38. slider = tk.Scale(root, from_=0, to=100, orient="horizontal", command=update)
  39. slider.pack(fill="x")
  40.  
  41. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment