From e43bf67c5b46d634179ad0c22f191f5daab12580 Mon Sep 17 00:00:00 2001 From: ROBINET Julien Date: Tue, 31 Mar 2026 10:36:47 +0200 Subject: [PATCH] =?UTF-8?q?+=20documentation=20(r=C3=A9=C3=A9lement=20cett?= =?UTF-8?q?e=20fois)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- projet_tkinter_sujet5.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/projet_tkinter_sujet5.py b/projet_tkinter_sujet5.py index ad9f887..f1f4abf 100644 --- a/projet_tkinter_sujet5.py +++ b/projet_tkinter_sujet5.py @@ -2,18 +2,19 @@ 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) + """fonction pour créer un carré de taille et de couleur aléatoire""" + lst = ["red", "blue", "green", "yellow", "grey"] #liste pour établir les différentes couleurs possibles + indice_couleur = randint(0, len(lst)-1) #choix de l'indice de lst (pour choisir une couleur) (aléatoire) + couleur = lst[indice_couleur] #établissement de la couleur choisie + taille = randint(10, 30) #choix de la taille (aléatoire) position_x = randint(0, 390) - position_y = randint(0, 290) - if position_x+taille > 400 : - taille = randint(10, 400-position_x) + position_y = randint(0, 290) #choix de la position du carré dans le canva (aléatoire) + if position_x+taille > 400 : #vérification que la taille et la position finale du carré ne dépase pas les limites + taille = randint(10, 400-position_x) #changement de la position suivant le résultat du booléen ci-dessus if position_y+taille > 300 : taille = randint(10, 300-position_y) rectangle = canva.create_rectangle(position_x, position_y, position_x+taille, - position_y+taille, fill = couleur) + position_y+taille, fill = couleur) #création du carré fenetre = tk.Tk() fenetre.title("Carrés aléatoires")