Browse Source

changement fonction spawn_rectangle avec un if

master
ROBINET Julien 4 weeks ago
parent
commit
361cb22224
  1. 9
      projet_tkinter_sujet5.py

9
projet_tkinter_sujet5.py

@ -8,14 +8,15 @@ def spawn_rectangle() :
taille = randint(10, 30) taille = randint(10, 30)
position_x = randint(0, 400) position_x = randint(0, 400)
position_y = randint(0, 300) position_y = randint(0, 300)
while position_x+taille > 400 or position_y+taille > 300: if position_x+taille > 400 :
taille = randint(10, 30) position_x = position_x-taille
position_x = randint(0, 400) if position_y+taille > 300 :
position_y = randint(0, 300) position_y = position_y-taille
rectangle = canva.create_rectangle(position_x, position_y, position_x+taille, rectangle = canva.create_rectangle(position_x, position_y, position_x+taille,
position_y+taille, fill = couleur) position_y+taille, fill = couleur)
fenetre = tk.Tk() fenetre = tk.Tk()
fenetre.title("Carrés aléatoires")
canva = tk.Canvas(fenetre, width = 400, height = 300, bg = "white") canva = tk.Canvas(fenetre, width = 400, height = 300, bg = "white")
canva.grid() canva.grid()

Loading…
Cancel
Save