Problème de def

Résolu/Fermé
AlpacinoNogeek Messages postés 12 Date d'inscription lundi 16 avril 2018 Statut Membre Dernière intervention 2 mars 2020 - Modifié le 16 avril 2018 à 16:09
AlpacinoNogeek Messages postés 12 Date d'inscription lundi 16 avril 2018 Statut Membre Dernière intervention 2 mars 2020 - 16 avril 2018 à 16:07
Bonjour,

J'ai eu quel ques problèmes quand je veut lancer mon jeux python (voilà la code):

from tkinter import *
from random import *
from tkinter.messagebox import*
import sys
from random import shuffle



fenetre=Tk()
fenetre.title('Licorne Invaders')
fenetre.geometry("640x480")
#creation de la fenetre de jeu



Fond=Canvas(fenetre,width=800,height=600,bg='black')
fichier6=PhotoImage(file="images/image_de _début.gif")
Fond.create_image(330,230,image=fichier6)
Fond.place(x=0,y=0)
#creation du canvas





def creation_plateforme():
global plateforme,xplateforme1,yplateforme1
plateforme=[]

xplateforme1=307
yplateforme1=450

#definition de x et y


def steam2():
global bou2, fichier, bou4,bou9,plateforme,xplateforme1,yplateforme1
bou4.destroy()
bou2.destroy()
bou9.destroy()
fichier=PhotoImage(file="images/SPACE.gif")
Fond.create_image(307,155,image=fichier)
plateforme.append(Fond.create_rectangle(xplateforme1,yplateforme1,xplateforme1+59,yplateforme1+17,fill='green'))
plateforme.append(fond.creat_rectangle(xplateforme1,yplateforme1,xplateforme1+20,yplateforme1+17,fill='grey'))


#steam2 est creee a partir d'un autre ecran de jeux qui n'a pas les meme bouttons, donc pour ne pas beuger, on crée une deuxieme fonction steam


def steam():
global bou2, fichier, bou4, bou3,
bou2.destroy()
bou3.destroy()
fichier=PhotoImage(file="images/SPACE.gif")
Fond.create_image(307,155,image=fichier)
plateforme.append(Fond.create_rectangle(xplateforme1,yplateforme1,xplateforme1+59,yplateforme1+17,fill='green'))





#creation de la fonction steam, fenetre de jeux principal

def liste():
global fichier3, bou3, bou2, bou4,bou7
bou1.destroy()
bou3.destroy()
bou7.destroy()
fichier3=PhotoImage(file="images/instru.gif")
Fond.create_image(320,240,image=fichier3)
bou4=Button(fenetre,text="Lancer le jeu !", command = start2)
bou4.pack()
#fonction liste pour les commandes


def credit():
global bou7, bou3, bou1, fichier5,bou9
bou7.destroy()
bou1.destroy()
bou3.destroy()
fichier5=PhotoImage(file="images/crédit.png")
Fond.create_image(320,240,image=fichier5)
bou9=Button(fenetre, text="Lancer le jeu !", command =start)
bou9.pack()
#fonction credits, pour nous, et une question de design (pour avoir 3 bouttons sur la premiere fenetre)



def start2():
global fichier2, bou2, bou1,bou3,bou7,fichier6,bou4
bou3.destroy()
bou1.destroy()
bou7.destroy()
bou4.destroy()
fichier2=PhotoImage(file="images/fond.png")
Fond.create_image(325,240,image=fichier2)
bou2=Button(fenetre,text="Je suis pret !", command = steam)
bou2.pack(side=BOTTOM)
#meme chose que pour la fonction steam2, on crée une deuxieme fonction strart



def start():
global fichier2, bou2, bou1,bou3,bou7,bou9
bou1.destroy()
bou3.destroy()
bou7.destroy()
bou9.destroy()
fichier2=PhotoImage(file="images/fond.png")
Fond.create_image(325,240,image=fichier2)
bou2=Button(fenetre,text="Je suis pret !", command = steam)
bou2.pack(side=BOTTOM)
#fonction start pour mettre le joueur dans une certaine ambiance


bou7=Button(fenetre, text="Crédits",command=credit)
bou7.pack(side=TOP)
bou3=Button(fenetre, text="Comment jouer ?", command =liste)
bou3.pack(side=BOTTOM)
bou1=Button(fenetre, text="Lancer le jeu !", command =start2)
bou1.place(x=277,y=220)
#premiers bouttons du menu de base




def move_plateforme(dx):
global xplateforme1,yplateforme1,drapeau,plateforme

xplateforme1=xplateforme1+dx




if xplateforme1<=35:
xplateforme1=35

Fond.coords(plateforme[0],xplateforme1,yplateforme1,xplateforme1+60,yplateforme1+20)


elif xplateforme1>=550:
xplateforme1=550

Fond.coords(plateforme[0],xplateforme1,yplateforme1,xplateforme1+60,yplateforme1+20)


else:
Fond.coords(plateforme[0],xplateforme1,yplateforme1,xplateforme1+60,yplateforme1+20)



def right(event):
move_plateforme(10)
fenetre.bind("<Key-Right>",right)
creation_plateforme()
def left(event):
move_plateforme(-10)
fenetre.bind("<Key-Left>",left)
def up(event) :
move_1plateforme(-10)




fenetre.mainloop()

try:
fenetre.destroy()
except TclError:
pass



Il m'affiche une erreur à la ligne 50, des idées pour y répondre ?

1 réponse

[Dal] Messages postés 6174 Date d'inscription mercredi 15 septembre 2004 Statut Contributeur Dernière intervention 2 février 2024 1 083
Modifié le 16 avril 2018 à 15:44
Salut AlpacinoNogeek,

Il manque une parenthèse fermante à la ligne précédente 44.

Ensuite, Python se plaindra d'autres problèmes, ailleurs dans le code :-)

Si tu postes du code sur le forum, tu rendras ton code lisible en utilisant pas les balises de <code python> permettant de préserver l'indentation de ton code, de colorer la syntaxe et numéroter tes lignes. Si tu n'as pas vu le bouton de l'éditeur te permettant de poster ton code correctement, il est là :


clique sur Python et met ton code entre les deux balises


Dal
0
AlpacinoNogeek Messages postés 12 Date d'inscription lundi 16 avril 2018 Statut Membre Dernière intervention 2 mars 2020
Modifié le 16 avril 2018 à 16:10
Merci beaucoup ! :) mais maintenant python se plaint de mes global :'( (Problème réglé, merci a toi Dal :D
0