Browse Source

+ fonction spawn_rectangle qui marche

master
ROBINET Julien 4 weeks ago
parent
commit
7d2cce5393
  1. 30
      projet_tkinter_sujet5.py

30
projet_tkinter_sujet5.py

@ -1,28 +1,19 @@
import tkinter as tk import tkinter as tk
from random import randint from random import randint
indice_couleur = randint(0, 4) def spawn_rectangle() :
couleur = 0 indice_couleur = randint(0, 4)
if indice_couleur == 0 : couleur = 0
if indice_couleur == 0 :
couleur = "red" couleur = "red"
if indice_couleur == 1 : if indice_couleur == 1 :
couleur = "green" couleur = "green"
if indice_couleur == 2 : if indice_couleur == 2 :
couleur = "blue" couleur = "blue"
if indice_couleur == 3 : if indice_couleur == 3 :
couleur = "yellow" couleur = "yellow"
if indice_couleur == 4 : if indice_couleur == 4 :
couleur = "grey" couleur = "grey"
#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, 31)#
# position_x = randint(0, 400)#
# position_y = randint(0, 300)#
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)
@ -38,9 +29,6 @@ fenetre = tk.Tk()
canva = tk.Canvas(fenetre, width = 400, height = 300, bg = "white") canva = tk.Canvas(fenetre, width = 400, height = 300, bg = "white")
canva.grid() canva.grid()
#rectangle = canva.create_rectangle(position_x, position_y, position_x+taille,# Dessin = tk.Button(fenetre, text = "Dessine", command = spawn_rectangle).grid()
# position_y+taille, fill = couleur)#
Dessin = tk.Button(fenetre, text = "Dessine", command = "spawn_rectangle").grid()
fenetre.mainloop() fenetre.mainloop()
Loading…
Cancel
Save