Advertisement
here2share

# tk_outline_text.py

Dec 31st, 2022
1,192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. # tk_outline_text.py
  2.  
  3. import tkinter as tk
  4. from PIL import Image, ImageDraw, ImageFont
  5.  
  6. root = tk.Tk()
  7. root.title("tk outline")
  8.  
  9. ww, hh = 600, 600
  10. root.geometry(f"{ww}x{hh}+10+10")
  11.  
  12. canvas = tk.Canvas(root, width=ww, height=hh, bg="white")
  13. canvas.pack()
  14.  
  15. img = Image.new('RGB', (ww, hh), 'white')
  16. draw = ImageDraw.Draw(img)
  17. font = ImageFont.truetype("Gabriola.ttf", 1400)
  18. draw.text((10, -420), u"\u03C0", font=font, fill="#000000")
  19.  
  20. outline = []
  21. for x in range(img.width):
  22.     for y in range(img.height):
  23.         if img.getpixel((x, y)) != (255, 255, 255):
  24.             if max(img.getpixel((x0, y0)) for x0, y0 in ((x+1,y), (x-1,y), (x,y+1), (x,y-1))) == (255, 255, 255):
  25.                 outline.append((x, y))
  26.  
  27. for x, y in outline:
  28.     canvas.create_rectangle(x, y, x+7, y+7, fill="#9433FF", width=0)
  29.  
  30. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement