1 changed files with 24 additions and 0 deletions
@ -0,0 +1,24 @@ |
|||||
|
from tkinter import * |
||||
|
import random |
||||
|
fenetre = Tk() |
||||
|
|
||||
|
def dessiner_carre(): |
||||
|
couleurs = ["red", "green", "blue", "yellow", "gray"] |
||||
|
couleur_utiliser = random.choice(couleurs) |
||||
|
taille = random.randint(10,30) |
||||
|
x = random.randint(0, 400 - taille) |
||||
|
y = random.randint(0, 300 - taille) |
||||
|
canvas.create_rectangle(x, y, x + taille, y + taille, fill=couleur_utiliser ) |
||||
|
|
||||
|
# canvas |
||||
|
canvas = Canvas(fenetre, width=400, height=300, background='black') |
||||
|
canvas.pack() |
||||
|
|
||||
|
bouton=Button(fenetre, text="Dessine", command=dessiner_carre) |
||||
|
bouton.pack() |
||||
|
# bouton de sortie |
||||
|
bouton=Button(fenetre, text="Fermer", command=fenetre.quit) |
||||
|
bouton.pack() |
||||
|
|
||||
|
fenetre.mainloop() |
||||
|
fenetre.destroy() |
Loading…
Reference in new issue