From 361cb22224ecd59acf4365d807db511e084f572c Mon Sep 17 00:00:00 2001 From: ROBINET Julien Date: Fri, 27 Mar 2026 14:53:30 +0100 Subject: [PATCH] changement fonction spawn_rectangle avec un if --- projet_tkinter_sujet5.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/projet_tkinter_sujet5.py b/projet_tkinter_sujet5.py index 017c178..e1bb867 100644 --- a/projet_tkinter_sujet5.py +++ b/projet_tkinter_sujet5.py @@ -8,14 +8,15 @@ def spawn_rectangle() : 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, 30) - position_x = randint(0, 400) - position_y = randint(0, 300) + if position_x+taille > 400 : + position_x = position_x-taille + if position_y+taille > 300 : + position_y = position_y-taille rectangle = canva.create_rectangle(position_x, position_y, position_x+taille, position_y+taille, fill = couleur) fenetre = tk.Tk() +fenetre.title("Carrés aléatoires") canva = tk.Canvas(fenetre, width = 400, height = 300, bg = "white") canva.grid()