Problème de menuP

Fermé
gangdlolol Messages postés 1 Date d'inscription mardi 8 mars 2016 Statut Membre Dernière intervention 8 mars 2016 - 8 mars 2016 à 09:29
 gangdlolol - 9 mars 2016 à 16:14
Bonjour,

J'essaye de créer un menu en python. A première vue, je ne vois pas de problème.

#Importer tout ce qui nous sera utile de Tkinter afin de créer une fenetre
from tkinter import *
#boîte de dialogue
from tkinter.messagebox import *


#Création d'une fenetre
fenetre = Tk()
#titre du labyrinthe
fenetre.title("Le layrinthe")
#couleur de fond
fenetre['bg']='black'

#création d'un panneau orienté de manière HORIZONTALE
p = PanedWindow(fenetre, orient=HORIZONTAL)
#Side va nous dire vers quel coté va s'orienter notre panneau. Expand va signidier si le panneau doit se develloper, ou non.
p.pack(side=TOP, expand=N, fill=BOTH, pady=30, padx=50)


#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
def menuP():
#Création du bouton jouer
boutonjouer = Button(p, text="Jouer", command = fenetre, width = 80, height = 4, background = "yellow" )

#Création du bouton paramètres
boutonparamètres = Button(p, text="Paramètres", command = paramètres, width = 80, height = 4, background = "yellow")

#Création du bouton quitter
boutonquitter = Button(p, text="Quitter", command = fenetre.destroy, width = 80, height = 4, background = "yellow")


boutonjouer.pack()
boutonparamètres.pack()
boutonquitter.pack()


def paramètres():
boutonparamètres.destroy()
boutonquitter.destroy()

fenetre['bg']='black'
fenetre.title("Paramètres")

echelle.pack(padx=10,pady=10)
boutonretour.pack()


def retour():
fenetre.title("Le layrinthe")

boutonretour.destroy()
echelle.destroy()
boutonjouer.destroy()

menuP.pack()

#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#Création du bouton jouer
boutonjouer = Button(p, text="Jouer", command = fenetre, width = 80, height = 4, background = "yellow" )
#Création du bouton paramètres
boutonparamètres = Button(p, text="Paramètres", command = paramètres, width = 80, height = 4, background = "yellow")
#Création du bouton quitter
boutonquitter = Button(p, text="Quitter", command = fenetre.destroy, width = 80, height = 4, background = "yellow")


Valeur = StringVar()
Valeur.set(1)

echelle = Scale(fenetre,from_=1,to=3,resolution=1,orient=HORIZONTAL, length=565,width=20,label="Niveau de difficulté",tickinterval=20,variable=Valeur)
echelle['bg']='yellow'

boutonretour = Button(p, text='retour', command = retour, width = 80, height = 4, background = "yellow")

#--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------




menuP.pack()

#Execution du panneau
p.pack()
#Execution de la fenetre
fenetre.mainloop()


Lorsque je lance ce programme, un message d'erreur s'affiche:

Traceback (most recent call last):
File "C:\Users\petit\Desktop\Tests python codes\testbouton (1).py", line 108, in <module>
menuP.pack()
AttributeError: 'function' object has no attribute 'pack'
>>>

Je ne comprends vraiment pas pourquoi ce message d'erreur s'affiche. Serait-il possible de m'aider?

Cordialement

gangdlolol

2 réponses

dsy73 Messages postés 9252 Date d'inscription dimanche 22 août 2010 Statut Contributeur Dernière intervention 23 octobre 2020 2 476
9 mars 2016 à 06:27
Salut
on ne peut pas lire ton code, utilise le bouton "code" pour l'afficher correctement dans l'éditeur de message.
0
jisisv Messages postés 3645 Date d'inscription dimanche 18 mars 2001 Statut Modérateur Dernière intervention 15 janvier 2017 934
9 mars 2016 à 13:03
D'autant plus que l'identation est essentielle en Python
0
#Importer tout ce qui nous sera utile de Tkinter afin de créer une fenetre 
from tkinter import * 
#boîte de dialogue 
from tkinter.messagebox import * 

#Création d'une fenetre 
fenetre = Tk() 
#titre du labyrinthe 
fenetre.title("Le layrinthe") 
#couleur de fond 
fenetre['bg']='black' 

#création d'un panneau orienté de manière HORIZONTALE 
p = PanedWindow(fenetre, orient=HORIZONTAL) 
#Side va nous dire vers quel coté va s'orienter notre panneau. Expand va signidier si le panneau doit se develloper, ou non. 
p.pack(side=TOP, expand=N, fill=BOTH, pady=30, padx=50) 

#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
def menuP(): 
#Création du bouton jouer 
       boutonjouer = Button(p, text="Jouer", command = fenetre, width = 80, height = 4, background = "yellow" ) 
#Création du bouton paramètres 
       boutonparamètres = Button(p, text="Paramètres", command = paramètres, width = 80, height = 4, background = "yellow") 
#Création du bouton quitter 
       boutonquitter = Button(p, text="Quitter", command = fenetre.destroy, width = 80, height = 4, background = "yellow") 
       boutonjouer.pack() 
       boutonparamètres.pack() 
       boutonquitter.pack() 

def paramètres(): 
       boutonparamètres.destroy() 
       boutonquitter.destroy() 
       fenetre['bg']='black' 
       fenetre.title("Paramètres") 
       echelle.pack(padx=10,pady=10) 
       boutonretour.pack() 

def retour(): 
       fenetre.title("Le layrinthe") 
       boutonretour.destroy() 
       echelle.destroy() 
       boutonjouer.destroy() 

menuP.pack() 
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
#Création du bouton jouer 
boutonjouer = Button(p, text="Jouer", command = fenetre, width = 80, height = 4, background = "yellow" ) 

#Création du bouton paramètres 
boutonparamètres = Button(p, text="Paramètres", command = paramètres, width = 80, height = 4, background = "yellow") 

#Création du bouton quitter 
boutonquitter = Button(p, text="Quitter", command = fenetre.destroy, width = 80, height = 4, background = "yellow") 

Valeur = StringVar() 
Valeur.set(1) 

echelle = Scale(fenetre, from_=1, to=3, resolution=1, orient=HORIZONTAL, length=565, width=20, label="Niveau de difficulté", tickinterval=20, variable=Valeur) 
echelle['bg']='yellow' 
boutonretour = Button(p, text='retour', command = retour, width = 80, height = 4, background = "yellow") 
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
menuP.pack() 

#Execution du panneau 
p.pack() 

#Execution de la fenetre 
fenetre.mainloop()
0