| 12
 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
 
 |  
 
# Importer le Toolkit wxPython
import wx
 
 
#-------------------------------------------------------------------------
class MenuFichier(wx.Frame):
    """Barre de menus déroulants"""
#-------------------------------------------------------------------------
    def __init__(self, parent):
       wx.Frame.__init__(self, parent)
       menu = wx.Menu()
       menu.Append(wx.ID_OPEN, "&Ouvrir\tCTRL+o")
       menu.Append(wx.ID_CLOSE, "&Fermer\tCTRL+f")
       menu.AppendSeparator()
       menu.Append(wx.ID_EXIT, "&Quitter\tCTRL+q")
       menuBarre = wx.MenuBar()
       menuBarre.Append(menu, "&Fichier")
       self.SetMenuBar(menuBarre)
 
 
#-------------------------------------------------------------------------
class InterfaceGraphique(wx.Panel):
    """Interface Graphique"""
#-------------------------------------------------------------------------
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self, parent, -1)
 
        b = wx.Button(self, -1, "Show the Menu sample", (50,50))
        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
 
 
    def OnButton(self, evt):
       win = MyFrame(self, -1, self.log)
       win.Show(True)
#-------------------------------------------------------------------------
 
#-------------------------------------------------------------------------
class Application(wx.Frame):
    """ Fenetre principale"""
#-------------------------------------------------------------------------
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)
        self.parent = parent
 
        # ------------------------------------------------------
        #    Initialisation du Menu
        # ------------------------------------------------------
        MenuFichier(parent)
 
        # ------------------------------------------------------
        #    Initialisation de l'interface graphique
        # ------------------------------------------------------
        InterfaceGraphique(parent)
 
 
#-------------------------------------------------------------------------
 
 
#-------------------------------------------------------------------------
class MonApp(wx.App):
#-------------------------------------------------------------------------
    def OnInit(self):
        frame = Application(None,-1,u'Fenêtre avec menus')
        frame.Show(True)
        self.SetTopWindow(frame)
        return True
#-------------------------------------------------------------------------
app = MonApp()
app.MainLoop() | 
Partager