# Draw a pyramid of bricks using tkinter Canvas from tkinter import * def draw_brick(x, y, bw, bh): # x, y are the co-ordinates of the top left corner of a brick # bw, bh are the width and height of a brick in pixels canvas.create_rectangle( x, y, x + bw, y + bh, outline="#fb0") # Set the colour of the brick outline ws = Tk() ws.title('Brick Pyramid') ws.geometry('600x600') ws.config(bg='#300') w = 500 h = 500 brickwidth = 30 brickheight = 15 canvas = Canvas( ws, height=h, width=w, bg="#fff" ) canvas.pack() ybase = 450 # Start near the bottom of the canvas xbase = 40 # Start near the left edge for num in range(14, 0, -1): # Bottom row has 14 bricks. Decrease by one brick each layer up xx = xbase for i in range(num): draw_brick(xx, ybase, brickwidth, brickheight) xx += brickwidth # Move right by one brick width # Move up one level ybase -= brickheight # y coordinate decreases by brick height xbase += (brickwidth // 2) # x start point shifts right by half a brick ws.mainloop()