CONNEXION
  • RetourJeux
    • Sorties
    • Hit Parade
    • Les + populaires
    • Les + attendus
    • Soluces
    • Tous les Jeux
    • Gaming
  • RetourActu Gaming
    • News
    • Astuces
    • Tests
    • Previews
    • Toute l'actu gaming
  • RetourBons plans
    • Bons plans
    • Bons plans Smartphone
    • Bons plans Hardware
    • Bons plans Image et Son
    • Bons plans Amazon
    • Bons plans Cdiscount
    • Bons plans Decathlon
    • Bons plans Fnac
    • Tous les Bons plans
  • RetourJVTech
    • Actus High-Tech
    • Intelligence Artificielle
    • Smartphones
    • Mobilité urbaine
    • Hardware
    • Image et son
    • Tutoriels
    • Tests produits High-Tech
    • Guides d'achat High-Tech
    • JVTech
  • RetourCulture
    • Actus Culture
    • Culture
  • RetourVidéos
    • A la une
    • Gaming Live
    • Vidéos Tests
    • Vidéos Previews
    • Gameplay
    • Trailers
    • Chroniques
    • Replay Web TV
    • Toutes les vidéos
  • RetourForums
    • Hardware PC
    • PS5
    • Switch 2
    • Xbox Series
    • Switch
    • Pokemon pocket
    • FC 25 Ultimate Team
    • League of Legends
    • Tous les Forums
  • PC
  • PS5
  • Xbox Series
  • Switch 2
  • PS4
  • One
  • Switch
  • iOS
  • Android
  • MMO
  • RPG
  • FPS
En ce moment Genshin Impact Valhalla Breath of the wild Animal Crossing GTA 5 Red dead 2
Liste des sujets

Une petite aide pour débuguer mon programme Python ?

Skeleex
Skeleex
Niveau 5
02 juin 2016 à 20:00:13

Forum Programmation Python Charte
Il n'est pas trop tard, rejoignez la communauté !
Inscrivez-vous »
C'est gratuit !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes.
Les membres n'ont pas de publicité
Posez votre question Signaler Messages d'Erreur pour mon programme...
Skeleex
Modifier
Bonjour, je dois faire un programme dans le cadre de la matière d'ISN... Celui-ci est le dernier, en deux fichier .py :
1 - v3.0.py
from tkinter import * #Nous utilisons Tkinter
from time import *
from random import *
from pendu1234 import *
fen=Tk()
c=Canvas(fen,cursor='pencil',width=800,height=600) #Dimensions Page+Curseur
fen.title('Blop & Cie')
c.pack()
def Clic(event):

  1. Interagir avec notre personnage

X = event.x
Y = event.y
if 50<X<240 and 350<Y<550 :
c.itemconfigure(perso,image=perso2)
fen.update()
sleep(3)
c.itemconfigure(perso,image=perso1)
fen.update()

  1. Aller dans le Tunnel

if 430<X<470 and 390<Y<420 :
c.itemconfigure(fond,image=fond2)
fen.update()

  1. retour fond de base

if 300<X<500 and 0<Y<100 :
c.itemconfigure(fond,image=fond1)
fen.update()

  1. Pendu

if 480<X<550 and 240<Y<300 :
pendu()
fond1 = PhotoImage(file="fond.gif")
fond2 = PhotoImage(file="fond2.gif")
perso1 = PhotoImage(file="perso1.gif") #On créé notre personnage
perso2 = PhotoImage(file="perso1.1.gif")
fond = c.create_image(400,300, image=fond1)
perso = c.create_image(150,450, image=perso1)
c.bind('<Button-1>', Clic) #clic gauche de la souris
fen.mainloop() #refresh
2 - python1234.py
from tkinter import *
from time import *
from random import choice
liste_mots =["JAMBON","MAISON","ECOLE","TRAVAIL","LOISIR","CHAT","TABLE","MUSIQUE","POISSON","CHIEN","BALLON"]
def lettre_dans_mot(lettre) :
global partie_en_cours, mot_partiel, mot_choisi, nb_echecs, image_pendu
if partie_en_cours :
nouveau_mot_partiel = ""
lettre_dans_mot = False
i=0
while i<len(mot_choisi):
if mot_choisi[i]==lettre:
nouveau_mot_partiel = nouveau_mot_partiel + lettre
lettre_dans_mot = True
else:
nouveau_mot_partiel = nouveau_mot_partiel + mot_partiel[i]
i+=1
mot_partiel = nouveau_mot_partiel
afficher_mot(mot_partiel) #vérifie si la lettre est bien dans le mot
if not lettre_dans_mot : # lettre fausse. Changer le dessin
nb_echecs += 1
nomFichier = "pendu_"+str(nb_echecs)+".gif"
photo=PhotoImage(file=nomFichier)
image_pendu.config(image=photo)
image_pendu.image=photo
if nb_echecs == 8: # trop d'erreurs. terminé
partie_en_cours = False
afficher_mot(mot_choisi)
fenetre = Tk()
bouton2 = Button(fenetre,text='Quitter',command=fenetre.quit)
bouton2.pack(side=RIGHT)
bouton1 = Button(fenetre,text='Recommencer',command=init_jeu)
bouton1.pack(side=RIGHT)
elif mot_partiel == mot_choisi: # le mot a été trouvé
partie_en_cours = False
def afficher_mot(mot):
global lettres
mot_large = ""
i=0
while i<len(mot): # ajoute un espace entre les lettres
mot_large = mot_large + mot[i] + " "
i+=1
canevas.delete(lettres)
lettres = canevas.create_text(320,60,text=mot_large,fill='black',font='Courrier 30')
def init_jeu():
global mot_choisi, mot_partiel, image_pendu, lettres, nb_echecs
global partie_en_cours, liste_mots
nb_echecs = 0
partie_en_cours = True
mot_choisi = choice(liste_mots).rstrip()
mot_choisi = mot_choisi.upper()
mot_partiel = "-" * len(mot_choisi)
canevas.delete(lettres)
afficher_mot(mot_partiel)
photo=PhotoImage(file="pendu_0.gif")
image_pendu.config(image=photo)
image_pendu.image=photo
def pendu () :
global fenetre,canevas,bouton,photo,image_pendu,lettres
fenetre = Tk()
fenetre.title("Le jeu du pendu")
canevas = Canvas(fenetre, bg='white', height=500, width=620)
canevas.pack(side=BOTTOM)
bouton = [0]*26
for i in range(26):
bouton[i] = Button(fenetre,text=chr(i+65),command=lambda x=i+65:lettre_dans_mot(chr(x)))
bouton[i].pack(side=LEFT)
photo=PhotoImage(file="pendu_0.gif")
image_pendu = Label(canevas, image=photo, border=0)
image_pendu.place(x=140, y=120)
lettres = canevas.create_text(320,60,text="",fill='black',font='Courrier 30')
init_jeu()
fenetre.mainloop()
fenetre.destroy()
Les messages d'erreur sont les suivants :
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
return self.func(*args)
File "E:\ISN projet\v3.0.py", line 32, in Clic
pendu()
File "E:\ISN projet\pendu1234.py", line 76, in pendu
image_pendu = Label(canevas, image=photo, border=0)
File "C:\Python33\lib\tkinter\__init__.py", line 2596, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "C:\Python33\lib\tkinter\__init__.py", line 2075, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: image "pyimage5" doesn't exist
Et lorsque je clique sur une lettre du pendu (en premier lieu, ça ne m'affiche pas d'image) :
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
return self.func(*args)
File "E:\ISN projet\pendu1234.py", line 72, in <lambda>
bouton[i] = Button(fenetre,text=chr(i+65),command=lambda x=i+65:lettre_dans_mot(chr(x)))
File "E:\ISN projet\pendu1234.py", line 7, in lettre_dans_mot
if partie_en_cours :
NameError: global name 'partie_en_cours' is not defined

Pseudo supprimé
Pseudo supprimé 02 juin 2016 à 20:04:07

RIP les espaces ...

Skeleex
Skeleex
Niveau 5
02 juin 2016 à 20:45:04

Effectivement.

145793
145793
Niveau 9
03 juin 2016 à 09:49:36

Y a un bug à la page 7 du paragre 72 alinéa 8. [[sticker:p/1kki]]

Sincèrement.. qu'es ce que tu veux comprendre un truc dans ton pavé.. de plus ici c'est informatique pas programmation.

De plus, si déjà sur un forum, t'es pas capable de mettre en page proprement ton code, j'ai pas envie de voir ton fichier code..[[sticker:p/1jne]]

Message édité le 03 juin 2016 à 09:51:00 par 145793
Pseudo supprimé
Pseudo supprimé 03 juin 2016 à 11:35:53

Plop.

J'ai pas mal utilisé tkinter, je pourrais t'aider mais là comme c'est presenté...j'ai pas trop.

Refais avec les balises code ou mp moi (mais proprement, pas un c/c degueulasse comme tu viens de faire )

Sous forums
  • Aide à l'achat Mac
  • Macintosh
  • Création de Jeux
  • Programmation
  • Création de sites web
  • Linux
  • Internet
  • Steam Deck
  • Hardware