Bonjour.
Je suis un étudiant de 1ère qui est le troisième mois sur python. Pour projet de fin d'année, je planifie un labyrinthe/donjon sur python et avant de découvrir tkinter, j'ai réussi à le faire qu'en refaisant print à chaque fois. Ici est mon ancien programme:
Il peut paraître long, mais c'est mon niveau actuel.
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110 def max_min(n): if n>32: n=33 elif n<0: n=0 return n def print_all(Screen,y,x): for e1 in range(max_min(y-3),max_min(y+4)): for e2 in range(max_min(x-3),max_min(x+4)): a=Screen[e1] element=a[e2] if element!=1: print(' ' if element==0 else "♗", end='') else: print('█', end='█') print() def print_full(Screen): for e1 in Screen: for e2 in e1: if e2!=1: print(' ' if e2==0 else "♗", end='') else: print('█', end='█') print() S0=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] S1=[1,0,1,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1] S2=[1,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1] S3=[1,0,1,0,1,0,0,1,0,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1] S4=[1,0,0,0,1,0,0,1,0,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1] S5=[1,0,1,0,1,0,0,1,0,1,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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32] char5="♗" char1="▇▇" char2="▓▓" x=16 y=16 stop_program=0 print_all(Screen,y,x) print("z pour monter, q pour aller à gauche, d pour aller à droite, s pour aller en bas et a pour arrêter") while stop_program==0: movement=str(input("Entrez la commande de mouvement : ")) if movement=="a": stop_program=1 elif movement=="z": t=Screen[y-1] if t[x]==0: t=Screen[y] t[x]=0 y=y-1 t=Screen[y] t[x]=5 print_all(Screen,y,x) elif movement=="s": t=Screen[y+1] if t[x]==0: t=Screen[y] t[x]=0 y=y+1 t=Screen[y] t[x]=5 print_all(Screen,y,x) elif movement=="q": t=Screen[y] if t[x-1]==0: t[x]=0 x=x-1 t=Screen[y] t[x]=5 print_all(Screen,y,x) elif movement=="d": t=Screen[y] if t[x+1]==0: t[x]=0 x=x+1 t=Screen[y] t[x]=5 print_all(Screen,y,x)
En découvrant tkinter, j'ai créé un second programme sensé marcher mais je ne sais pas ce qui cloche, c'est ma première semaine avec tkinter
Je ne comprends pas quelle est l'erreur, et voici pourquoi je lance un appel à l'aide.
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146 def max_min(n): if n>32: n=33 elif n<0: n=0 return n def print_all(Screen,y,x): for e1 in range(max_min(y-3),max_min(y+4)): for e2 in range(max_min(x-3),max_min(x+4)): a=Screen[e1] element=a[e2] if element!=1: print(' ' if element==0 else "♗", end='') else: print('█', end='█') print() def print_full(Screen): for e1 in Screen: for e2 in e1: if e2!=1: print(' ' if e2==0 else "♗", end='') else: print('█', end='█') print() def valid(): global x x = validation.get() print(validation.get()) def modification(): if label["text"]: label["text"] = "" else: label["text"] = print_all(Screen,y,x) def z(x,y,Screen): t=Screen[y-1] if t[x]==0: t=Screen[y] t[x]=0 y=y-1 t=Screen[y] t[x]=5 def s(x,y,Screen): t=Screen[y-1] if t[x]==0: t=Screen[y] t[x]=0 y=y+1 t=Screen[y] t[x]=5 def q(x,y,Screen): t=Screen[y-1] if t[x]==0: t=Screen[y] t[x]=0 x=x-1 t=Screen[y] t[x]=5 def d(x,y,Screen): t=Screen[y-1] if t[x]==0: t=Screen[y] t[x]=0 x=x+1 t=Screen[y] t[x]=5 S0=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] S1=[1,0,1,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1] S2=[1,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1] S3=[1,0,1,0,1,0,0,1,0,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1] S4=[1,0,0,0,1,0,0,1,0,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1] S5=[1,0,1,0,1,0,0,1,0,1,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1] S6=[1,0,1,0,1,0,0,1,0,1,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1] S7=[1,0,1,0,1,0,0,1,0,1,1,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1] S8=[1,0,1,0,1,1,0,1,0,1,1,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1] S9=[1,0,1,0,0,1,0,1,0,1,1,0,0,0,0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,1,1,1,1,1,1,1,1,1,0,1] S24=[1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1] S25=[1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1] S26=[1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1] S27=[1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1] S28=[1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1] S29=[1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1] S30=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1] S31=[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1] S32=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] Screen=[S0,S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12,S13,S14,S15,S16,S17,S18,S19,S20,S21,S22,S23,S24,S25,S26,S27,S28,S29,S30,S31,S32] char5="♗" char1="▇▇" char2="▓▓" x=16 y=16 e0 = Tk() Label( e0, text="Bienvenue dans ce jeu. Vous devrez cocher cette case pour commencer.", ).pack(side=TOP, padx=20, pady=10) validation=IntVar() validé = Checkbutton(e0, text="Je commence!", variable=validation, command=valid and e0.destroy, ).pack(side=LEFT, padx=20, pady=10) e1 = Tk() label = Label(e1, text="Gamepad") label.pack() Bouton1 = Button(e1, text ='haut', command = z(x,y,Screen) and print(print_all(Screen,y,x))) Bouton1.pack(side = TOP, padx = 5, pady = 5) Bouton2 = Button(e1, text ='droite', command = d(x,y,Screen) and print(print_all(Screen,y,x))) Bouton2.pack(side = RIGHT, padx = 5, pady = 5) Bouton3 = Button(e1, text ='gauche', command = q(x,y,Screen) and print(print_all(Screen,y,x))) Bouton3.pack(side = LEFT, padx = 5, pady = 5) Bouton4 = Button(e1, text ='bas', command = s(x,y,Screen) and print(print_all(Screen,y,x))) Bouton4.pack(side = BOTTOM, padx = 5, pady = 5) e1.mainloop()
La photographie viendra dans un commentaire de ce sue je veux que ça donne, et ça devrait s'actualiser sur le même "label"
Merci de votre attention.
Partager