Animation programme Python
Résolu/Fermé
Utilisateur anonyme
-
Naacs -
Naacs -
Bonjour, je cherche à animer mon jeux avec quelque chose de sympa mais je ne sais comment faire...
Voici mon programme :
Et voilà ce que je veux obtenir à peux près :
Merci d'avance pour votre aide.
EDIT: Ajout de la coloration syntaxique.
Voici mon programme :
from tkinter import * from tkinter.messagebox import * # boîte de dialogue import random def reponse(event): global compteur if resultat.get() == m: # le mot de passe est bon : on affiche une boîte de dialogue puis on ferme la fenêtre #showinfo('Résultat','Bonne réponse') compteur+=1 #else: # le mot de passe est incorrect : on affiche une boîte de dialogue #showwarning('Résultat','Mauvaise réponse !') #resultat.set('') Mafenetre.destroy() def calcul_effectue(choix,a,b): if choix.get() == 1: return a+b elif choix.get() == 2: return a-b else : return a*b def affichage_calcul(choix,a,b): if choix.get() == 1: return str(a)+"+"+str(b) elif choix.get() == 2: return str(a)+"-"+str(b) else : return str(a)+"x"+str(b) def choise(): if choix.get() in range(1,4): fen.destroy() else: fen.destroy() showwarning('Calcul mental','Fin du jeu') exit(1) fen=Tk() fen.title('Menu') fen.geometry("300x300") labelsomme = Label(fen,text='Somme : taper 1') labelsoustraction = Label(fen,text='Soustraction : taper 2') labelmultiplication = Label(fen,text='Multiplication : taper 3') labelquitter = Label(fen,text='Quitter : taper 4') labelsomme.grid(row=0,column=0) labelsoustraction.grid(row=1,column=0) labelmultiplication.grid(row=2,column=0) labelquitter.grid(row=3,column=0) choix= IntVar() Champ1 = Entry(fen,textvariable= choix,bg ='bisque', fg='maroon') Champ1.delete(0,END) #choix.set("entrer votre choix") Champ1.grid(row=4,column=0) Champ1.focus_set() Champ1.selection_range(0,END) Bouton1 = Button(fen, text ='Valider', command = choise) Bouton1.grid(row=5,column=0) fen.mainloop() compteur = 0 resultat = None for i in range(5): print(i) # Création de la fenêtre principale (main window) Mafenetre = Tk() Mafenetre.title('Jeu de Calcul Mental') Mafenetre.update() Mafenetre.geometry("300x300") nbre1=random.randint(1,10) nbre2=random.randint(1,10) m=calcul_effectue(choix,nbre1,nbre2) # Création d'un widget Label (texte 'le calcul à effectué') Frame1 = Frame(Mafenetre, borderwidth=2, relief=GROOVE) Frame1.pack(side=TOP, padx=5, pady=5) Label(Frame1, text=affichage_calcul(choix,nbre1,nbre2)).pack(padx=5, pady=10) # Création d'un widget Label (texte 'votre réponse') Frame2 = Frame(Mafenetre, borderwidth=2, relief=GROOVE,width=25) Frame2.pack(side=BOTTOM ,padx=5, pady=20) Label(Frame2, text="votre réponse").pack(padx=5, pady=10) # Création d'un widget Entry (champ de saisie) resultat= IntVar() Champ = Entry(Frame2, textvariable= resultat,bg ='bisque', fg='maroon',width=25) Champ.delete(0,END) Champ.pack(side = LEFT, padx = 5, pady = 30) Champ.bind("<Return>",reponse) Champ.focus_set() Champ.selection_range(0,END) # Création d'un widget Button (bouton Valider) #Bouton = Button(Frame2, text ='Valider', command = reponse) #Bouton.pack(side = BOTTOM, padx = 5, pady = 40) # Création d'un widget Label (texte 'compteur') Frame2 = Frame(Mafenetre, borderwidth=2, relief=GROOVE) Frame2.pack(side=BOTTOM, padx=5, pady=50) Label(Frame2, text="compteur "+str(compteur)+" sur " + str(i)).pack(padx=5, pady=10) Mafenetre.mainloop() Mafenetre2 = Tk() Mafenetre2.title('Pourcentage obtenu') Mafenetre2.geometry("500x300") labelpourcentage = Label(Mafenetre2,text='Pourcentage obtenu : '+ str(compteur*100/5)+" %") labelpourcentage.pack(side = TOP, padx=5, pady=10) Mafenetre2.mainloop() photo = PhotoImage(file=".png") canvas = Canvas(fenetre,width=800, height=600) canvas.create_image(0, 0, anchor=NW, image=photo) canvas.pack()
Et voilà ce que je veux obtenir à peux près :

Merci d'avance pour votre aide.
EDIT: Ajout de la coloration syntaxique.
A voir également:
- Animation programme Python
- Citizen code python avis - Accueil - Outils
- Programme demarrage windows - Guide
- Message programmé iphone - Guide
- Mettre en veille un programme - Guide
- Programme word gratuit - Guide
4 réponses
Salut
le code n'est pas lisible, utilise le bouton "Code" dans l'éditeur pour activer la coloration syntaxique stp.
le code n'est pas lisible, utilise le bouton "Code" dans l'éditeur pour activer la coloration syntaxique stp.
Utilisateur anonyme
Bonjour, je viens de corriger cela
dsy73
Messages postés
9252
Date d'inscription
Statut
Contributeur
Dernière intervention
2 485
>
Utilisateur anonyme
Merci
Utilisateur anonyme
Merci
Ton code fonctionne, il suffisait de mettre mainloop() à la fin et de choisir la bonne fenêtre pour afficher ton image.
Lorsque tu lances ton programme, il est préférable de le faire dans une console pour voir tous les message d'erreur. Tu avais une erreur à la fermeture.
Mafenetre2 = Tk() Mafenetre2.title('Pourcentage obtenu') Mafenetre2.geometry("500x300") labelpourcentage = Label(Mafenetre2,text='Pourcentage obtenu : '+ str(compteur*100/5)+" %") labelpourcentage.pack(side = TOP, padx=5, pady=10) photo = PhotoImage(file="test.png") canvas = Canvas(Mafenetre2, width=800, height=600) canvas.create_image(0, 0, anchor=NW, image=photo) canvas.pack() Mafenetre2.mainloop()
Lorsque tu lances ton programme, il est préférable de le faire dans une console pour voir tous les message d'erreur. Tu avais une erreur à la fermeture.
from tkinter import * from tkinter.messagebox import * # boîte de dialogue import random def reponse(event): global compteur if resultat.get() == m: # le mot de passe est bon : on affiche une boîte de dialogue puis on ferme la fenêtre #showinfo('Résultat','Bonne réponse') compteur+=1 #else: # le mot de passe est incorrect : on affiche une boîte de dialogue #showwarning('Résultat','Mauvaise réponse !') #resultat.set('') Mafenetre.destroy() def calcul_effectue(choix,a,b): if choix.get() == 1: return a+b elif choix.get() == 2: return a-b else : return a*b def affichage_calcul(choix,a,b): if choix.get() == 1: return str(a)+"+"+str(b) elif choix.get() == 2: return str(a)+"-"+str(b) else : return str(a)+"x"+str(b) def choise(): if choix.get() in range(1,4): fen.destroy() else: fen.destroy() showwarning('Calcul mental','Fin du jeu') exit(1) fen=Tk() fen.title('Menu') fen.geometry("300x300") labelsomme = Label(fen,text='Somme : taper 1') labelsoustraction = Label(fen,text='Soustraction : taper 2') labelmultiplication = Label(fen,text='Multiplication : taper 3') labelquitter = Label(fen,text='Quitter : taper 4') labelsomme.grid(row=0,column=0) labelsoustraction.grid(row=1,column=0) labelmultiplication.grid(row=2,column=0) labelquitter.grid(row=3,column=0) choix= IntVar() Champ1 = Entry(fen,textvariable= choix,bg ='bisque', fg='maroon') Champ1.delete(0,END) #choix.set("entrer votre choix") Champ1.grid(row=4,column=0) Champ1.focus_set() Champ1.selection_range(0,END) Bouton1 = Button(fen, text ='Valider', command = choise) Bouton1.grid(row=5,column=0) fen.mainloop() compteur = 0 resultat = None for i in range(5): print(i) # Création de la fenêtre principale (main window) Mafenetre = Tk() Mafenetre.title('Jeu de Calcul Mental') Mafenetre.update() Mafenetre.geometry("300x300") nbre1=random.randint(1,10) nbre2=random.randint(1,10) m=calcul_effectue(choix,nbre1,nbre2) # Création d'un widget Label (texte 'le calcul à effectué') Frame1 = Frame(Mafenetre, borderwidth=2, relief=GROOVE) Frame1.pack(side=TOP, padx=5, pady=5) Label(Frame1, text=affichage_calcul(choix,nbre1,nbre2)).pack(padx=5, pady=10) # Création d'un widget Label (texte 'votre réponse') Frame2 = Frame(Mafenetre, borderwidth=2, relief=GROOVE,width=25) Frame2.pack(side=BOTTOM ,padx=5, pady=20) Label(Frame2, text="votre réponse").pack(padx=5, pady=10) # Création d'un widget Entry (champ de saisie) resultat= IntVar() Champ = Entry(Frame2, textvariable= resultat,bg ='bisque', fg='maroon',width=25) Champ.delete(0,END) Champ.pack(side = LEFT, padx = 5, pady = 30) Champ.bind("<Return>",reponse) Champ.focus_set() Champ.selection_range(0,END) # Création d'un widget Button (bouton Valider) #Bouton = Button(Frame2, text ='Valider', command = reponse) #Bouton.pack(side = BOTTOM, padx = 5, pady = 40) # Création d'un widget Label (texte 'compteur') Frame2 = Frame(Mafenetre, borderwidth=2, relief=GROOVE) Frame2.pack(side=BOTTOM, padx=5, pady=50) Label(Frame2, text="compteur "+str(compteur)+" sur " + str(i)).pack(padx=5, pady=10) Mafenetre.mainloop() Mafenetre2 = Tk() Mafenetre2.title('Pourcentage obtenu') Mafenetre2.geometry("500x300") labelpourcentage = Label(Mafenetre2,text='Pourcentage obtenu : '+ str(compteur*100/5)+" %") labelpourcentage.pack(side = TOP, padx=5, pady=10) Mafenetre2.mainloop() photo = PhotoImage(file=".png") canvas = Canvas(fenetre,width=800, height=600) canvas.create_image(0, 0, anchor=NW, image=photo) canvas.pack() Mafenetre2.mainloop()
from tkinter import * from tkinter.messagebox import * # boîte de dialogue import random def reponse(event): global compteur if resultat.get() == m: # le mot de passe est bon : on affiche une boîte de dialogue puis on ferme la fenêtre #showinfo('Résultat','Bonne réponse') compteur+=1 #else: # le mot de passe est incorrect : on affiche une boîte de dialogue #showwarning('Résultat','Mauvaise réponse !') #resultat.set('') Mafenetre.destroy() def calcul_effectue(choix,a,b): if choix.get() == 1: return a+b elif choix.get() == 2: return a-b else : return a*b def affichage_calcul(choix,a,b): if choix.get() == 1: return str(a)+"+"+str(b) elif choix.get() == 2: return str(a)+"-"+str(b) else : return str(a)+"x"+str(b) def choise(): if choix.get() in range(1,4): fen.destroy() else: fen.destroy() showwarning('Calcul mental','Fin du jeu') exit(1) fen=Tk() fen.title('Menu') fen.geometry("300x300") labelsomme = Label(fen,text='Somme : taper 1') labelsoustraction = Label(fen,text='Soustraction : taper 2') labelmultiplication = Label(fen,text='Multiplication : taper 3') labelquitter = Label(fen,text='Quitter : taper 4') labelsomme.grid(row=0,column=0) labelsoustraction.grid(row=1,column=0) labelmultiplication.grid(row=2,column=0) labelquitter.grid(row=3,column=0) choix= IntVar() Champ1 = Entry(fen,textvariable= choix,bg ='bisque', fg='maroon') Champ1.delete(0,END) #choix.set("entrer votre choix") Champ1.grid(row=4,column=0) Champ1.focus_set() Champ1.selection_range(0,END) Bouton1 = Button(fen, text ='Valider', command = choise) Bouton1.grid(row=5,column=0) fen.mainloop() compteur = 0 resultat = None for i in range(5): print(i) # Création de la fenêtre principale (main window) Mafenetre = Tk() Mafenetre.title('Jeu de Calcul Mental') Mafenetre.update() Mafenetre.geometry("300x300") nbre1=random.randint(1,10) nbre2=random.randint(1,10) m=calcul_effectue(choix,nbre1,nbre2) # Création d'un widget Label (texte 'le calcul à effectué') Frame1 = Frame(Mafenetre, borderwidth=2, relief=GROOVE) Frame1.pack(side=TOP, padx=5, pady=5) Label(Frame1, text=affichage_calcul(choix,nbre1,nbre2)).pack(padx=5, pady=10) # Création d'un widget Label (texte 'votre réponse') Frame2 = Frame(Mafenetre, borderwidth=2, relief=GROOVE,width=25) Frame2.pack(side=BOTTOM ,padx=5, pady=20) Label(Frame2, text="votre réponse").pack(padx=5, pady=10) # Création d'un widget Entry (champ de saisie) resultat= IntVar() Champ = Entry(Frame2, textvariable= resultat,bg ='bisque', fg='maroon',width=25) Champ.delete(0,END) Champ.pack(side = LEFT, padx = 5, pady = 30) Champ.bind("<Return>",reponse) Champ.focus_set() Champ.selection_range(0,END) # Création d'un widget Button (bouton Valider) #Bouton = Button(Frame2, text ='Valider', command = reponse) #Bouton.pack(side = BOTTOM, padx = 5, pady = 40) # Création d'un widget Label (texte 'compteur') Frame2 = Frame(Mafenetre, borderwidth=2, relief=GROOVE) Frame2.pack(side=BOTTOM, padx=5, pady=50) Label(Frame2, text="compteur "+str(compteur)+" sur " + str(i)).pack(padx=5, pady=10) Mafenetre.mainloop() Mafenetre2 = Tk() Mafenetre2.title('Pourcentage obtenu') Mafenetre2.geometry("500x300") labelpourcentage = Label(Mafenetre2,text='Pourcentage obtenu : '+ str(compteur*100/5)+" %") labelpourcentage.pack(side = TOP, padx=5, pady=10) Mafenetre2.mainloop() photo = PhotoImage(file=".png") canvas = Canvas(fenetre,width=800, height=600) canvas.create_image(0, 0, anchor=NW, image=photo) canvas.pack()