commit 4df285d1a3cca3ed1b083bb147d60168c7adfaa4 Author: Laine <> Date: Mon Mar 24 09:21:12 2025 +0100 mon projet diff --git a/projet-tk_inter_arthur.py b/projet-tk_inter_arthur.py new file mode 100644 index 0000000..7b5e054 --- /dev/null +++ b/projet-tk_inter_arthur.py @@ -0,0 +1,33 @@ +from tkinter import * +import random + +fenetre = Tk() + +canvas = Canvas(fenetre, width=400, height=300, background='white') +canvas.grid() + +def carre(): + x1 = random.randint(0,400) + largeur_aleatoire = random.randint(10,30) + x2 = x1 + largeur_aleatoire + y1 = random.randint(0,300) + y2 = y1 + largeur_aleatoire + couleur = random.choice(["red", "green", "blue", "yellow", "grey"]) + if x2 > 400 or y2 > 300 or y1 == 0 or x1 == 0 or y1 == 300 or x1 == 400: + while x2 > 400 or y2 >300 or y1 == 0 or x1 == 0 or y1 == 300 or x1 == 400: + x1 = random.randint(0,400) + x_intermédiaire = random.randint(10,30) + x2 = x1 + x_intermédiaire + y1 = random.randint(0,300) + y2 = y1 + x_intermédiaire + couleur = random.choice(["red", "green", "blue", "yellow", "grey"]) + else: + carré = canvas.create_rectangle(x1, y1, x2, y2, fill= couleur, outline = couleur) + canvas.grid() + + +bouton=Button(fenetre, text="Dessine", command= carre) +bouton.grid() + +fenetre.mainloop() +fenetre.destroy() \ No newline at end of file