From 9345969918955f267dcecbc170cf6fb8eac63f38 Mon Sep 17 00:00:00 2001 From: ROBINET Julien Date: Fri, 27 Mar 2026 17:27:55 +0100 Subject: [PATCH] =?UTF-8?q?+=20r=C3=A9glages=20taille=20des=20carr=C3=A9s?= =?UTF-8?q?=20(demande=20du=20prof)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- projet_tkinter_sujet5.py | 50 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/projet_tkinter_sujet5.py b/projet_tkinter_sujet5.py index e1bb867..9ed4328 100644 --- a/projet_tkinter_sujet5.py +++ b/projet_tkinter_sujet5.py @@ -1,26 +1,26 @@ -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) - 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() - -Dessin = tk.Button(fenetre, text = "Dessine", command = spawn_rectangle).grid() - +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, 390) + position_y = randint(0, 290) + if position_x+taille > 400 : + taille = randint(10, 400-position_x) + 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) + +fenetre = tk.Tk() +fenetre.title("Carrés aléatoires") + +canva = tk.Canvas(fenetre, width = 400, height = 300, bg = "white") +canva.grid() + +Dessin = tk.Button(fenetre, text = "Dessine", command = spawn_rectangle).grid() + fenetre.mainloop() \ No newline at end of file