Skip to content

Instantly share code, notes, and snippets.

@tiborsaas
Created November 26, 2016 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiborsaas/6158e01f3ab5baa30dbc4e8fde6a73e8 to your computer and use it in GitHub Desktop.
Save tiborsaas/6158e01f3ab5baa30dbc4e8fde6a73e8 to your computer and use it in GitHub Desktop.
import tkinter as tk # using Python 3
size = 600
m = tk.Tk()
canvas = tk.Canvas(m, width=size, height=size)
canvas.pack()
pos = 0
scale = 1/3
def rect(n, x, y, size, color):
global scale
if n == 0:
return
canvas.create_rectangle( x, y, x+size, y+size, fill=color, width='0' )
rect( n-1, x, y + size/3, size * scale, '#0099ff' ) # left
rect( n-1, x + size/3, y, size * scale, '#99ff00' ) # top
rect( n-1, x + size/3, y + size/3*2, size * scale, 'orange' ) # bottom
rect( n-1, x + size/3*2, y + size/3, size * scale, 'blue' ) # right
rect( 5, 0, 0, size, 'yellow' )
m.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment