Bonsoir , voila mon petit soucis , je dois faire un menu déroulant mais obligatoirement en POO . J'arrive à creer ma fenêtre mais aucun menu dessus comment faire ? Alors qu'en procédural tout fonctionne correctement
Voila mon code et merci d'avance
from tkinter import *
class Fenetre():
def __init__(self):
self.fenetre_accueil=Tk() # creation de la fenetre
self.fenetre_accueil.title("fenetre")# donner un titre a une fenetre
self.menubar = Menu(self.fenetre_accueil)
def execution_accueil(self):
self.fenetre_accueil.mainloop() #executer la creation de la fenetre
class Bar_Menu(Fenetre):
def __init__(self):# Pq ais-je du remetre l'attribut nom ?
Fenetre.__init__(self)
def Client_Menu(self):
menu_client = Menu(self.menubar, tearoff=0)
menu_client.add_command(label="Ajout")#, command=donothing)
menu_client.add_command(label="Supression")#, command=donothing)
menu_client.add_command(label="Modification")#, command=donothing)
menu_client.add_separator()# souligner le "Exit"
menu_client.add_command(label="Exit", command=self.fenetre_accueil.destroy)
self.menubar.add_cascade(label="Client", menu=menu_client)# Preciser que le menu doit etre en cascade
fenetre=Bar_Menu()
fenetre.Client_Menu()
fenetre.execution_accueil()
Voila , j'ai reussi a mettre mon menu déroulant mais je voudrais ouvrir une fenetre lorsque j'appui sur le bouton suivant mais elle s'ouvre mais avec rien dessu
Voila mon fichier contenant mon menu-deroulant:
from tkinter import*
class MenuBar(Frame):
"""Barre de menus deroulants"""
def __init__(self, boss =None):
Frame.__init__(self, borderwidth =2, relief =GROOVE)
#---------------------------------------------------------------------------------#
##### Menu <Client> #####
fileMenu_client = Menubutton(self, text ="Client")
fileMenu_client.grid(row=0,column=0)
# Partie "deroulante" :
menu_client = Menu(fileMenu_client,tearoff=0)
menu_client.add_command(label ="Ajout")#,command = boss.effacer)
menu_client.add_command(label="Supression")#, command=self.donothing)
menu_client.add_command(label="Modification")#, command=self.donothing)
# Integration du menu :
fileMenu_client.configure(menu = menu_client )
#---------------------------------------------------------------------------------#
##### Menu <Devis> #####
fileMenu_devis = Menubutton(self, text ="Devis")
fileMenu_devis.grid(row=0,column=1)
# Partie "deroulante" :
menu_devis = Menu(fileMenu_devis,tearoff=0)
menu_devis.add_command(label="Creation")#,command = boss.effacer)
menu_devis.add_command(label="Modification")#, command=self.donothing)
menu_devis.add_command(label="Supression")#, command=self.donothing)
# Integration du menu :
fileMenu_devis.configure(menu = menu_devis)
#---------------------------------------------------------------------------------#
##### Menu <facture> #####
fileMenu_facture = Menubutton(self, text ="Facture")
fileMenu_facture.grid(row=0,column=2)
# Partie "deroulante" :
menu_facture = Menu(fileMenu_facture,tearoff=0)
menu_facture.add_command(label="Recherche")#,command = boss.effacer)
menu_facture.add_command(label="Creation")#, command=self.donothing)
# Integration du menu :
fileMenu_facture.configure(menu = menu_facture)
#---------------------------------------------------------------------------------#
##### Menu <stock> #####
fileMenu_stock = Menubutton(self, text ="Stock")
fileMenu_stock.grid(row=0,column=3)
# Partie "deroulante" :
menu_stock = Menu(fileMenu_stock, tearoff=0)
menu_stock .add_command(label="Stock")#, command=donothing)
menu_stock .add_command(label="Ajout")#, command=donothing)
menu_stock .add_command(label="Modification")#, command=donothing)
menu_stock .add_command(label="Supression")#, command=donothing)
# Integration du menu :
fileMenu_stock.configure(menu = menu_stock)
#---------------------------------------------------------------------------------#
##### Menu <aide> #####
fileMenu_aide = Menubutton(self, text ="Aide")
fileMenu_aide.grid(row=0,column=4)
# Partie "deroulante" :
menu_aide = Menu(fileMenu_aide, tearoff=0)
menu_aide.add_command(label="Client")#, command=donothing)
menu_aide.add_command(label="Devis")#, command=donothing)
menu_aide.add_command(label="Facture")#, command=donothing)
menu_aide.add_command(label="Stock")#, command=donothing)
# Integration du menu :
fileMenu_aide.configure(menu = menu_aide)
#---------------------------------------------------------------------------------#
et mais programme principale :
from menu_1 import *
class Test(MenuBar,Frame):
def __init__(self, boss =None):
Frame.__init__(self)
self.grid()
self.master.title('Fenetre avec menus')
mBar = MenuBar(self)
mBar.grid(row=0,column=0)
self.master.geometry("400x300+200+200")
#self.master.config(bg ="cadet blue")
bouton= n() # pour signaler que la command concernant le bouton est dans la class n
buton=Button(text="Quitter",fg="red",command=bouton.nou)
buton.grid(row=1,column=0)
#self.master.destroy()
class n(MenuBar):
def __init__(self, boss =None):
Frame.__init__(self)
self.grid()
def nou(self):
#self.f=Tk()
#self.f.title('Fenetre menus')
fenetre=Tk()
mBar = MenuBar(self)
mBar.grid(row=0,column=0)
buton=Button(text="Quitter",fg="red")
buton.grid(row=1,column=0)
print("couou")
fenetre.mainloop()
if __name__ =="__main__": # --- Programme de test ---
Test().mainloop()
merci d'avance
- Edité par algra 9 février 2013 à 19:00:27
Tkinter menu en cascade
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.