Bonjour

Voici mon soucis, j'essaye tant bien que mal de créer une fonction ( j'ai lu sur des sites qu'il est préférable d'utiliser ramdon ? ) qui crée des rectangles aléatoires dans mon canvas.
J'ai retourné mon script de toutes les façons possible et dont je suis capable, sans résultats. Je m’abandonne à vous merci pour votre aide.
J'ai oublié de préciser ( au cas ou sa ne se voit pas assez avec mon script) que je suis débutante en langage tkinter


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 
from tkinter import *
from random import randrange
 
 
def nouveau_jeu():
    a=0
def rectangle():
    d=0
    b=2
    c=10
    while d<3:
       can1.create_rectangle(10+c, 10+c, 100+c, 100+c)
       d=d+1
       c=c+100
 
def pomme(): 
    a=0
    x=randrange(840)
    y=randrange(480)
    i=0
    i2=0
    while i<rectangle:
        i2=1
 
def perso(): #personnage
    global dx, dy, x, y, nana, direction
    nana=can1.create_rectangle(20,20,50,50)
 
def avant(event):
    global dx, dy, x, y,nana, direction
    direction=1
    dx=0
    dy=-10
    x=x+10
    y=y+10
    can1.move(nana, dx, dy)
 
def gauche(event):
    global dx, dy, nana
    direction=2
    dx=-10
    dy=0
    can1.move(nana, dx, dy)
 
def droite(event):
    global dx, dy, nana
    direction=3
    dx=10
    dy=0
    can1.move(nana, dx, dy)
    direction=0
 
def bas(event):
    global dx, dy, nana
    dx=0
    dy=10
    can1.move(nana, dx, dy)
 
fen1=Tk()
fen1.title("SUPER NANA ! :D")
can1= Canvas (fen1, bg='blue', height=480, width=840)
can1.grid(row=0, column=0, rowspan=10)
can1.bind_all("<Up>", avant)
can1.bind_all("<Right>", droite)
can1.bind_all("<Down>", bas)
can1.bind_all("<Left>", gauche)
Button(fen1, text="Nouveau Jeu", font=("ComicSansMS"), command=perso).grid(row =4, column=1, sticky=N, padx=5)
Button(fen1, text="Quitter", font=("ComicSansMS"),command=fen1.destroy).grid(row =6, column=1, sticky=N)
x=randrange(840)
y=randrange(480)
dx=0
dy=0
direction=0
score=0
fen1.mainloop()