1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| #########################################################################
# Importation de fonctions externes :
from tkinter import *
#########################################################################
# Définition locale de fonctions :
class MenuBar(Frame):
"""Barre de menus déroulants"""
def __init__(self , boss = None):
Frame.__init__(self , borderwidth = 2)
##### menu <Fichier> #####
fileMenu = Menubutton(self , text = "Fichier" , font = ("Times" , 11 , "bold") , underline = 0)
fileMenu.pack(side = LEFT)
# partie déroulante menu Fichier
menu1 = Menu(fileMenu)
menu1.add_command(label = "Effacer" , underline = 0 , command = boss.effacer)
menu1.add_separator() # ajout d'une ligne séparatrice
menu1.add_command(label = "Quitter" , underline = 0 , command = boss.quit)
# intégration du menu
fileMenu.configure(menu = menu1)
##### menu <Client> #####
self.client = Menubutton(self , text = "Clients" , font = ("Times" , 11 , "bold") , underline = 0)
self.client.pack(side = LEFT , padx = 4)
# partie déroulante menu clients
menu1 = Menu(self.client)
menu1.add_command(label = "Animaux" , underline = 0 , command = boss.showAnim)
menu1.add_command(label = "Maîtres" , underline = 0 , command = boss.showMaitr)
# intégration du menu
self.client.configure(menu = menu1)
##### menu <Interventions> #####
self.inter = Menubutton(self , text = "Interventions" , font = ("Times" , 11 , "bold") , underline = 0)
self.inter.pack(side = LEFT , padx = 4)
# partie déroulante menu interventions
menu1 = Menu(self.inter)
menu1.add_command(label = "Actes" , underline = 0 , command = boss.castr)
menu1.add_command(label = "Ventes" , underline = 0 , command = boss.showVente)
# sous-menu
menu2 = Menu(menu1)
menu2.add_command(label = "Activyl" , underline = 2 , command = boss.activyl)
menu2.add_command(label = "Adequan" , underline = 2 , command = boss.adequan)
menu2.add_command(label = "Advocate" , underline = 3 , command = boss.advocate)
# intégration sous-menu
menu1.add_cascade(label = "Médicaments" , underline = 0 , menu = menu2)
# intégration du menu
self.inter.configure(menu = menu1)
class Application(Frame):
"""Application principale"""
def __init__(self , boss = None):
Frame.__init__(self)
self.master.title("Fenêtre avec menus")
menBar = MenuBar(self)
menBar.pack()
self.canva = Canvas(self , bg = "light grey" , height = 190 , width = 250 , borderwidth = 2)
self.canva.pack()
self.pack()
def effacer(self):
self.canva.delete(ALL)
def showAnim(self):
self.canva.create_text(10 , 10 , anchor = NW , text = "Utah")
def showMaitr(self):
self.canva.create_text(60 , 10 , anchor = NW , text = "Orane")
def castr(self):
self.canva.create_text(150 , 10 , anchor = NW , text = "Castration")
def showVente(self):
self.canva.create_text(150 , 30 , anchor = NW , text = "Croquettes")
def activyl(self):
self.canva.create_text(150 , 50 , anchor = NW , text = "Anti-puce")
def adequan(self):
self.canva.create_text(150 , 70 , anchor = NW , text = "Arthrite")
def advocate(self):
self.canva.create_text(150 , 90 , anchor = NW , text = "Infection parasitaires")
#########################################################################
# Corps principal du programme
if __name__ == "__main__":
app = Application()
app.mainloop() |
Partager