Ecran titre de jeu

Bonjour,
je suis débutante en python et je dois créer un jeu qui consiste à faire gonfler un ballon jusqu'à une punaise. Le jeu fonctionne mais j'aimerais créer un écran titre pour le jeu, contenant un bouton démarrer qui lancerait toutes mes fonctions. Comment faire ?
Merci d'avance

1 réponse

  • Votes
  • Date
  • Date décroissante
  1. Contributeur
    Salut

    difficile de te répondre car tu n'indiques pas comment tu as créé ton jeu. PyGame n'est pas la seule bibliothèque existante. Qu'utilises-tu ?

    Sinon tu crées un nouvel écran, non ?
    1. Désolée, j'utilise Tkinter

      Voilà mon code:
      from Tkinter import*
      import time

      fen1=Tk()
      fen1.title("Le plus grand des ballons")

      size=20
      now=time.time()
      future=now+4

      def jeu():
      cadre=Canvas
      cadre=Canvas(fen1,width=700, height=550, bg="black")
      x=280
      y=320
      ballon=cadre.create_oval(x-size, y-size, x+size, y+size, fill="pink")

      def commencer():
      cadre.itemconfigure(ballon, fill="pink")
      start.destroy()

      def pomper():
      global size
      if size<90:
      size=size+6
      cadre.coords(ballon, x-size, y-size, x+size, y+size)
      if size>90:
      cadre.delete(ballon)
      cadre.create_text (700/2, 550/2, text="PERDU! Ton ballon a éclaté", fill='cyan', font='Arial 45')
      if size>80 and size<87 and time.time()<future and time.time()>future-1:
      cadre.create_text (700/2, 550/2, text="BRAVO! C'est parfait", fill='cyan', font='Arial 45')
      cadre.delete(ballon)
      if size<79 and size>62 and time.time()<future and time.time()>future-1:
      cadre.create_text (700/2, 550/2, text="BOF! C'est moyen", fill='cyan', font='Arial 45')
      cadre.delete(ballon)
      if size<61 and time.time()<future and time.time()>future-1:
      cadre.create_text (700/2, 550/2, text="NUL! Entraine toi", fill='cyan', font='Arial 45')
      cadre.delete(ballon)

      def stop():
      fen1.destroy()

      #écran titre
      ecrantitre=Canvas(fen1,width=700, height=550, bg="black")
      start=Button(fen1, text="jouer!", command=jeu)

      start.pack()

      #autres widgets

      pomper=Button(fen1, text="Souffle", command=pomper)
      pomper.pack()

      fen1.mainloop()

      Quand j'essaie de faire fonctionner le programme, il me dit "pomper is not defined" pourtant la fonction est bien définie et je pense que cela est lié au fait qu'elle soit incluse elle même dans la fonction "jeu"
      je ne sais pas du tout comment faire
    2. Contributeur
      @ninouillelanouilleC'est impossible de lire ton code correctement car l'indentation est absente, edites ton message et utilise le bouton "Code" stp.

      Je suis surpris que tu utilises le même nom pour la fonction et le bouton. Vérifie ton code.
    3. from Tkinter import*
      import time

      fen1=Tk()
      fen1.title("Le plus grand des ballons")

      size=20
      now=time.time()
      future=now+4

      def jeu():
      x=280
      y=320
      ballon=cadre.create_oval(x-size, y-size, x+size, y+size, fill="pink")

      def commencer():
      cadre.itemconfigure(ballon, fill="pink")
      start.destroy()

      def souffler():
      global size
      if size<90:
      size=size+6
      cadre.coords(ballon, x-size, y-size, x+size, y+size)
      if size>90:
      cadre.delete(ballon)
      cadre.create_text (700/2, 550/2, text="PERDU! Ton ballon a éclaté", fill='cyan', font='Arial 45')
      if size>80 and size<87 and time.time()<future and time.time()>future-1:
      cadre.create_text (700/2, 550/2, text="BRAVO! C'est parfait", fill='cyan', font='Arial 45')
      cadre.delete(ballon)
      if size<79 and size>62 and time.time()<future and time.time()>future-1:
      cadre.create_text (700/2, 550/2, text="BOF! C'est moyen", fill='cyan', font='Arial 45')
      cadre.delete(ballon)
      if size<61 and time.time()<future and time.time()>future-1:
      cadre.create_text (700/2, 550/2, text="NUL! Entraine toi", fill='cyan', font='Arial 45')
      cadre.delete(ballon)

      def stop():
      fen1.destroy()

      #écran titre
      ecrantitre=Canvas(fen1,width=700, height=550, bg="black")
      start=Button(fen1, text="jouer!", command=jeu)
      start.pack()

      #autres widgets

      cadre=Canvas
      cadre=Canvas(fen1,width=700, height=550, bg="black")
      pomper=Button(fen1, text="Souffle", command=souffler)
      pomper.pack()
      quitter=Button(fen1, text="quitter", command=stop)
      quitter.pack()

      fen1.mainloop()
    4. Contributeur
      @ninouillelanouilleSimplifie ton code, en fait il y a plein d'erreurs : indentation, fonction dans fonction, etc
      Relis ton cours sur l'accès aux variables.
    5. @dsy73Je suis au courant qu'il y a des erreurs, sinon je ne demanderais pas d'aide...
      Je n'ai aucun cours.
      Enfin merci quand même