Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_mosaic.py
- from Tkinter import*
- from PIL import Image, ImageDraw
- from random import randint
- ww = 600
- hh = 600
- root = Tk()
- root.title("Tk Mosaic")
- root.geometry("%dx%d+0+0"%(ww,hh))
- canvas = Canvas(root, width=ww, height=hh)
- canvas.grid()
- def rgb2hex():
- return '#{:02x}{:02x}{:02x}'.format(r,g,b)
- SQUARE_SIZE = 8
- for y in range(0, hh, SQUARE_SIZE):
- for x in range(0, ww, SQUARE_SIZE):
- r,g,b = [randint(0, 255) for _ in 'rgb']
- canvas.create_rectangle([(x, y), (x + SQUARE_SIZE, y + SQUARE_SIZE)], fill=rgb2hex())
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement