Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_outline_text.py
- import tkinter as tk
- from PIL import Image, ImageDraw, ImageFont
- root = tk.Tk()
- root.title("tk outline")
- ww, hh = 600, 600
- root.geometry(f"{ww}x{hh}+10+10")
- canvas = tk.Canvas(root, width=ww, height=hh, bg="white")
- canvas.pack()
- img = Image.new('RGB', (ww, hh), 'white')
- draw = ImageDraw.Draw(img)
- font = ImageFont.truetype("Gabriola.ttf", 1400)
- draw.text((10, -420), u"\u03C0", font=font, fill="#000000")
- outline = []
- for x in range(img.width):
- for y in range(img.height):
- if img.getpixel((x, y)) != (255, 255, 255):
- 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):
- outline.append((x, y))
- for x, y in outline:
- canvas.create_rectangle(x, y, x+7, y+7, fill="#9433FF", width=0)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement