[wxPython-users] i cant see ma second frame; program is not
subclassing; values r not passed from frames to frames
Werner F. Bruhin
werner.bruhin at free.fr
Mon Aug 20 08:22:56 PDT 2007
Hi Yadin,
yadin Bocuma Rivas wrote:
> hi i have this programm some one told me is because my program is not =
> sublassing
> but i do not know what he means....
> how can i make my variables valid outside defined classes ; so that =
> they can be appended by other textCtrls belonging to another =
> frames(frames defined independently in other clases ) please if it is =
> confusing here is ma program
Enclosing code is not very easy to use as all the indentation gets lost, =
you are better attaching the files.
Attached a small program with two frames, change the value in the text =
ctrl and click on the button on the first frame.
Hope this helps
Werner
-------------- next part --------------
#Boa:Frame:Frame2
import wx
def create(parent):
return Frame2(parent)
[wxID_FRAME2, wxID_FRAME2PANEL1, wxID_FRAME2TEXTCTRL1, =
] =3D [wx.NewId() for _init_ctrls in range(3)]
class Frame2(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=3DwxID_FRAME2, name=3D'', parent=3Dprnt,
pos=3Dwx.Point(811, 329), size=3Dwx.Size(400, 250),
style=3Dwx.DEFAULT_FRAME_STYLE, title=3D'Frame2')
self.SetClientSize(wx.Size(384, 214))
self.panel1 =3D wx.Panel(id=3DwxID_FRAME2PANEL1, name=3D'panel1', p=
arent=3Dself,
pos=3Dwx.Point(32, 32), size=3Dwx.Size(200, 100),
style=3Dwx.TAB_TRAVERSAL)
self.textCtrl1 =3D wx.TextCtrl(id=3DwxID_FRAME2TEXTCTRL1, name=3D't=
extCtrl1',
parent=3Dself.panel1, pos=3Dwx.Point(72, 32), size=3Dwx.Size(=
100, 21),
style=3D0, value=3D'textCtrl1')
def __init__(self, parent):
self._init_ctrls(parent)
-------------- next part --------------
#!/usr/bin/env python
#Boa:App:BoaApp
import wx
import Frame1
modules =3D{'Frame1': [1, 'Main frame of Application', u'Frame1.py'],
'Frame2': [0, '', u'Frame2.py']}
class BoaApp(wx.App):
def OnInit(self):
self.main =3D Frame1.create(None)
self.main.Show()
self.SetTopWindow(self.main)
return True
def main():
application =3D BoaApp(0)
application.MainLoop()
if __name__ =3D=3D '__main__':
main()
-------------- next part --------------
#Boa:Frame:Frame1
import Frame2
import wx
def create(parent):
return Frame1(parent)
[wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1PANEL1, =
] =3D [wx.NewId() for _init_ctrls in range(3)]
class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=3DwxID_FRAME1, name=3D'', parent=3Dprnt,
pos=3Dwx.Point(547, 303), size=3Dwx.Size(400, 250),
style=3Dwx.DEFAULT_FRAME_STYLE, title=3D'Frame1')
self.SetClientSize(wx.Size(384, 214))
self.panel1 =3D wx.Panel(id=3DwxID_FRAME1PANEL1, name=3D'panel1', p=
arent=3Dself,
pos=3Dwx.Point(176, 80), size=3Dwx.Size(200, 100),
style=3Dwx.TAB_TRAVERSAL)
self.button1 =3D wx.Button(id=3DwxID_FRAME1BUTTON1,
label=3D'Get value from textctrl', name=3D'button1',
parent=3Dself.panel1, pos=3Dwx.Point(64, 32), size=3Dwx.Size(=
75, 23),
style=3D0)
self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
id=3DwxID_FRAME1BUTTON1)
def __init__(self, parent):
self._init_ctrls(parent)
=
self.frame2 =3D Frame2.Frame2(self)
self.frame2.Show()
=
=
def OnButton1Button(self, event):
caption =3D 'Value from textctrl'
msg =3D 'value from textctrl: %s' % self.frame2.textCtrl1.GetValue()
dlg =3D wx.MessageDialog(self, msg, caption, wx.OK | wx.ICON_INFORM=
ATION)
try:
result =3D dlg.ShowModal()
finally:
dlg.Destroy()
=20
More information about the wxpython-users
mailing list