Je suis essayer de creer un petit GUI application avec wxPython.
Pour la clarté du code de source je veux séparer le GUI-code et le 'vrai' code:

(j'ai creé une petite application test. Un Frame avec un button et label, can je presse sur le button le label va changer).

Maincode:
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
 
import wx
import gui
 
class TestApp(wx.App):
    def OnInit(self):
        self.main = gui.create(None)
        self.main.Show()
        self.SetTopWindow(self.main)
        return True
 
def main():
    application = TestApp(0)
    application.MainLoop()
 
if __name__ == '__main__':
    main()
 
def OnButton1Click(event):
    gui.Frame1.Label1.Label = 'zever'

gui.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
 
import wx
import main
 
def create(parent):
    return Frame1(parent)
 
[wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1LABEL1, wxID_FRAME1PANEL1, 
] = [wx.NewId() for _init_ctrls in range(4)]
 
class Frame1(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(239, 326), size=wx.Size(414, 266),
              style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
        self.SetClientSize(wx.Size(406, 239))
 
        self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
              pos=wx.Point(0, 0), size=wx.Size(406, 239),
              style=wx.TAB_TRAVERSAL)
 
        self.Label1 = wx.StaticText(id=wxID_FRAME1LABEL1, label='Label1',
              name='Label1', parent=self.panel1, pos=wx.Point(152, 56),
              size=wx.Size(31, 13), style=0)
 
        self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label='button1',
              name='button1', parent=self.panel1, pos=wx.Point(136, 104),
              size=wx.Size(75, 23), style=0)
        self.button1.Bind(wx.EVT_BUTTON, main.OnButton1Click,
              id=wxID_FRAME1BUTTON1)
 
    def __init__(self, parent):
        self._init_ctrls(parent)
ça ne marche pas,
Quand je presse le button Python retourne le erreur "AttributeError: type object 'Frame1' has no attribute 'Label1'"
J'ai deja essayé beaucoup de variants sur la ligne 'gui.Frame1.Label1.Label = 'zever'', mais rien marche

Quelqu'n qui sais comment je peut fais ça?