1 changed files with 25 additions and 25 deletions
@ -1,26 +1,26 @@ |
|||||
import tkinter as tk |
import tkinter as tk |
||||
from random import randint |
from random import randint |
||||
|
|
||||
def spawn_rectangle() : |
def spawn_rectangle() : |
||||
lst = ["red", "blue", "green", "yellow", "grey"] |
lst = ["red", "blue", "green", "yellow", "grey"] |
||||
indice_couleur = randint(0, len(lst)-1) |
indice_couleur = randint(0, len(lst)-1) |
||||
couleur = lst[indice_couleur] |
couleur = lst[indice_couleur] |
||||
taille = randint(10, 30) |
taille = randint(10, 30) |
||||
position_x = randint(0, 390) |
position_x = randint(0, 390) |
||||
position_y = randint(0, 290) |
position_y = randint(0, 290) |
||||
if position_x+taille > 400 : |
if position_x+taille > 400 : |
||||
taille = randint(10, 400-position_x) |
taille = randint(10, 400-position_x) |
||||
if position_y+taille > 300 : |
if position_y+taille > 300 : |
||||
taille = randint(10, 300-position_y) |
taille = randint(10, 300-position_y) |
||||
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") |
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() |
||||
|
|
||||
Dessin = tk.Button(fenetre, text = "Dessine", command = spawn_rectangle).grid() |
Dessin = tk.Button(fenetre, text = "Dessine", command = spawn_rectangle).grid() |
||||
|
|
||||
fenetre.mainloop() |
fenetre.mainloop() |
||||
Loading…
Reference in new issue