-
February 7th, 2010, 05:19 AM
#1
wxPython object properties
How can I change the properties of an object when it's created in another file?
Check this example:
It's a simple form with a label and a button, when you click on the button the label must change to something else. To keep my code readable I want the GUI-creation in another file:
This is the mainfile:
Code:
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'
And the GUI-file
Code:
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)
I can click the button and the code (which is in the mainfile) is executed, but I cannot find how to change the label itself. In this example I get the error "AttributeError: type object 'Frame1' has no attribute 'Label1'. What's the right syntax for this? Keeping this all in one file, there's no problem, but I really want it to be splitted
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|