You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
825 B
25 lines
825 B
import tkinter as tk
|
|
from random import randint
|
|
|
|
def spawn_rectangle() :
|
|
lst = ["red", "blue", "green", "yellow", "grey"]
|
|
indice_couleur = randint(0, len(lst)-1)
|
|
couleur = lst[indice_couleur]
|
|
taille = randint(10, 30)
|
|
position_x = randint(0, 400)
|
|
position_y = randint(0, 300)
|
|
while position_x+taille > 400 or position_y+taille > 300:
|
|
taille = randint(10, 31)
|
|
position_x = randint(0, 400)
|
|
position_y = randint(0, 300)
|
|
rectangle = canva.create_rectangle(position_x, position_y, position_x+taille,
|
|
position_y+taille, fill = couleur)
|
|
|
|
fenetre = tk.Tk()
|
|
|
|
canva = tk.Canvas(fenetre, width = 400, height = 300, bg = "white")
|
|
canva.grid()
|
|
|
|
Dessin = tk.Button(fenetre, text = "Dessine", command = spawn_rectangle).grid()
|
|
|
|
fenetre.mainloop()
|