bonjour, je souhaiterai créer une fenêtre principale et ajouter un menubar à cette fenêtre. Pour cela j'aimerai pouvoir utiliser un module "menus" dans lequel j'y mettrais tous les menus, ainsi que les evenements et les methodes. L'idée serait d'avoir un module menu indépendant que j'utiliserai dans mes différentes applications.
Est ce que quelqu'un pourrais m'expliquer pourquoi il ne se passe rien dans ma fenêtre principale lorsque je clic sur les boutons de mon menu. J'aimerai bien pouvoir fermer mon application, par exemple, ou voir s'afficher mon "Coucou"
Vous trouverez, ci joints, les codes de ma fenetre principale et celui de mon module Menus. J'avoue que je suis perplexe et que je suis complétement bloqué.
Si quelqu'un peut m'aider ...! merci d'avance.
Module wxTempo.py
Et mon module wxMenus.py
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #!/usr/bin/python # -*- coding: cp1252 -*- # Importer le Toolkit wxPython try: import wx except ImportError: raise ImportError, "The wxPython module is required to run this program." # Importer les menus try: import wxMenus except ImportError: raise ImportError, "Cette application nécessite le module wxMenus." #------------------------------------------------------------------------- class wxFenetre(wx.Frame): """ Fenêtre principale""" #------------------------------------------------------------------------- def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title) # ---------------------------------------------------------------- # Initialisation du Menu fenêtre principale # ---------------------------------------------------------------- MonMenuFichier = wxMenus.MenuPrincipal(parent=self) #------------------------------------------------------------------------- #------------------------------------------------------------------------- class MonApp(wx.App): #------------------------------------------------------------------------- def OnInit(self): frame = wxFenetre(None,-1,u'Fenêtre avec menus') frame.Show(True) self.SetTopWindow(frame) return True app = MonApp() app.MainLoop() #-------------------------------------------------------------------------
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #!/usr/bin/python # -*- coding: cp1252 -*- # Importer le Toolkit wxPython try: import wx except ImportError: raise ImportError, "The wxPython module is required to run this program." #------------------------------------------------------------------------- class MenuPrincipal(wx.MenuBar): """Barre de menus deroulants""" #------------------------------------------------------------------------- def __init__(self, parent): wx.MenuBar.__init__(self) # Prepare the menu bar menuBar = wx.MenuBar() # ---------------------------------------------------------------- # Menu Fichier # ---------------------------------------------------------------- mFichier = wx.Menu() mFichier.Append(wx.ID_OPEN, "&Ouvrir\tCTRL+O") mFichier.Append(wx.ID_CLOSE, "&Fermer\tCTRL+F") mFichier.AppendSeparator() mFichier.Append(wx.ID_EXIT, "&Quitter\tCTRL+Q") # Add menu to the menu bar menuBar.Append(mFichier, "&Fichier") # ---------------------------------------------------------------- # Menu Partie # ---------------------------------------------------------------- mPlay = wx.Menu() mPlay.Append(101, "&Coucou\tCTRL+C") # Add menu to the menu bar menuBar.Append(mPlay, "&Partie") # ---------------------------------------------------------------- # Lancement de la barre de menu dans fenêtre principale # ---------------------------------------------------------------- parent.SetMenuBar(menuBar) # Menu events self.Bind(wx.EVT_MENU, self.CloseWindow, id=wx.ID_EXIT) self.Bind(wx.EVT_MENU, self.Coucou, id=101) # Methods def CloseWindow(self, event): self.Close() def Coucou(self, event): print "Coucou"
Partager