Problème de menuP
gangdlolol
Messages postés
1
Date d'inscription
Statut
Membre
Dernière intervention
-
gangdlolol -
gangdlolol -
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
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
Salut
on ne peut pas lire ton code, utilise le bouton "code" pour l'afficher correctement dans l'éditeur de message.
on ne peut pas lire ton code, utilise le bouton "code" pour l'afficher correctement dans l'éditeur de message.
jisisv
Messages postés
3645
Date d'inscription
Statut
Modérateur
Dernière intervention
934
D'autant plus que l'identation est essentielle en Python
#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()