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
|
# -*- coding: utf-8 -*-
from Tkinter import *
MesImage = {}
class MenuBar(Frame):
"""Barre de menus déroulants"""
def __init__(self, boss =None):
Frame.__init__(self, borderwidth =2)
##### Menu <Fichier> #####
MesImage["imageTest"] = PhotoImage(file = "noir_jaune.gif")
fileMenu = Menubutton(self, image = MesImage["imageTest"])
fileMenu.pack(side =LEFT)
# Partie "déroulante" :
me1 = Menu(fileMenu)
me1.add_command(label ='Effacer', underline =0,
command = boss.effacer)
me1.add_command(label ='Terminer', underline =0,
command = boss.quit)
# Intégration du menu :
fileMenu.configure(menu = me1)
class Application(Frame):
"""Application principale"""
def __init__(self, boss =None):
Frame.__init__(self)
self.master.title('Fenêtre avec menus')
mBar = MenuBar(self)
mBar.pack()
self.can = Canvas(self, bg='light grey', height=190,
width=250, borderwidth =2)
self.can.pack()
self.pack()
def effacer(self):
self.can.delete(ALL)
if __name__ == '__main__':
app = Application()
app.mainloop() |
Partager