Share your text data anonymously and free
from tkinter import *
from random import randint
root = Tk()
root.title("Shapes")
canvas = Canvas(root, width=400, height=400)
canvas.pack()
shapes = []
def create_shape(event):
shape = choice(["oval", "rectangle", "triangle"])
x = randint(0, 350)
y = randint(0, 350)
if shape == "oval":
x0 = x - 50
y0 = y - 50
x1 = x + 50
y1 = y + 50
s = canvas.create_oval(x0, y0, x1, y1, fill="red")
elif shape == "rectangle":
x0 = x - 50
y0 = y - 50
x1 = x + 50
y1 = y + 50
s = canvas.create_rectangle(x0, y0, x1, y1, fill="blue")
else:
s = canvas.create_polygon(x, y-50, x-50, y+50, x+50, y+50, fill="green")
shapes.append(s)
canvas.bind("<Button-1>", create_shape)
root.mainloop()