A voir également:
- Probleme sur python
- Citizen code python avis - Accueil - Outils
- Python est introuvable. exúcutez sans argument pour procúder ó l ✓ - Forum Python
- Mot secret python pix ✓ - Forum Python
- Python par la pratique : 101 exercices corrigés pdf - Forum Python
- Exercice python - Forum Python
1 réponse
Bonjour,
Voici ma proposition en Python3.6
Note: n'ayant pastes images, j'en ai mis d'autres: à toi de remettre les tiennes.
Qu'ai-je changé ?
J'ai déplacé la ligne "x1, y1 = x1+dx, y1+dy", supprimé ce qui concernait "oval1" car c'est en fait "imageL", déplacé "initialisation()", remplacé dans clic() "global personnage" par "global personnage1" mais je ne vois pas l'intérêt de ce global ni du test "if personnage1 == "Clou":", ...
Ritchi
Voici ma proposition en Python3.6
Note: n'ayant pastes images, j'en ai mis d'autres: à toi de remettre les tiennes.
# -*- coding: utf-8 -*- from tkinter import * def initialisation(): global photoL, imageL, personnage1, photoH, imageH, personnage2, photoD, imageD photoD = PhotoImage(file="MonDecor.gif") imageD = can1.create_image(406,305, image=photoD) photoH = PhotoImage(file="MonClou.gif") imageH = can1.create_image(50,50,anchor=CENTER, image=photoH) photoL = PhotoImage(file="MonTableau.gif") imageL = can1.create_image(60,50,anchor=CENTER, image=photoL) can1.pack() personnage1 = "Clou" personnage2 = "Tableau" def depl_clou(x,y): print("depl_clou") can1.coords(imageH, x, y) def config_clou(): global personnage1 print("config_clou") personnage1="Clou" def clic(event): global personnage1 print("clic") if personnage1 == "Clou": depl_clou(event.x, event.y) def move(): global x1, y1, dx, dy, flag print("move") if x1 > 210: x1, dx, dy = 210, 0, 15 if y1 > 210: y1, dx, dy = 210, -15, 0 if x1 < 10: x1, dx, dy = 10, 0, -15 if y1 < 10: y1, dx, dy = 10, 15, 0 x1, y1 = x1+dx, y1+dy can1.coords(imageL, x1, y1) if flag >0: print("flag>0") fen1.after(50,move) def stop_it(): global flag print("stop_it") flag=0 def start_it(): global flag print("start_it") if flag == 0: flag=1 move() print("init") x1, y1 = 10, 10 dx, dy = 15, 0 flag = 0 fen1 = Tk() can1 = Canvas(fen1, bg='dark grey', height=610, width=812) can1.pack(side=LEFT, padx=5, pady=5) initialisation() # oval1 = can1.create_image(20,50,anchor=CENTER,image=photoL) bou1 = Button(fen1, text="Quitter", width=8, command=fen1.quit) bou1.pack() bou2 = Button(fen1, text="Démarrer", width=8, command=start_it) bou2.pack() bou3 = Button(fen1, text="Arrêter", width=8, command=stop_it) bou3.pack() can1.bind("<Button-1>", clic) fen1.mainloop()
Qu'ai-je changé ?
J'ai déplacé la ligne "x1, y1 = x1+dx, y1+dy", supprimé ce qui concernait "oval1" car c'est en fait "imageL", déplacé "initialisation()", remplacé dans clic() "global personnage" par "global personnage1" mais je ne vois pas l'intérêt de ce global ni du test "if personnage1 == "Clou":", ...
Ritchi