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()