Advertisement
here2share

# Tk_mosaic.py

Aug 30th, 2021
1,490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. # Tk_mosaic.py
  2.  
  3. from Tkinter import*
  4.  
  5. from PIL import Image, ImageDraw
  6. from random import randint
  7.  
  8. ww = 600
  9. hh = 600
  10. root = Tk()
  11. root.title("Tk Mosaic")
  12. root.geometry("%dx%d+0+0"%(ww,hh))
  13. canvas = Canvas(root, width=ww, height=hh)
  14. canvas.grid()
  15.  
  16. def rgb2hex():
  17.     return '#{:02x}{:02x}{:02x}'.format(r,g,b)
  18.  
  19. SQUARE_SIZE = 8
  20.  
  21. for y in range(0, hh, SQUARE_SIZE):
  22.     for x in range(0, ww, SQUARE_SIZE):
  23.         r,g,b = [randint(0, 255) for _ in 'rgb']
  24.         canvas.create_rectangle([(x, y), (x + SQUARE_SIZE, y + SQUARE_SIZE)], fill=rgb2hex())
  25.  
  26. canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement