help to make program better

math2life QJing.Li at gmail.com
Fri Aug 17 13:07:51 EDT 2007


On Aug 17, 9:27 am, yadin <conra2... at yahoo.com> wrote:
> hi!
> Can any one tell me why is it that i can't see my second frame and why
> is the value of freq not Appended in the First frame ...thanks
> I know it is wx python  but it has to do with passing variables.thanks
>
> import wx
>
> def create(parent):
>     return Frame1(parent)
>
> [wxID_FRAME1, wxID_FRAME1FREQ, wxID_FRAME1FREQDISP,
> wxID_FRAME1STATICTEXT1,
> ] = [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(380, 179), size=wx.Size(241, 133),
>               style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
>         self.SetClientSize(wx.Size(233, 99))
>
>         self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,
>               label='frequency disp', name='staticText1', parent=self,
>               pos=wx.Point(24, 32), size=wx.Size(71, 13), style=0)
>
>         self.freqdisp = wx.TextCtrl(id=wxID_FRAME1FREQDISP,
> name='freqdisp',
>               parent=self, pos=wx.Point(104, 24), size=wx.Size(100,
> 21),
>               style=0, value='')
>
>         self.freq = wx.Button(id=wxID_FRAME1FREQ, label='get freq',
> name='freq',
>               parent=self, pos=wx.Point(24, 56), size=wx.Size(184,
> 23),
>               style=0)
>         self.freq.Bind(wx.EVT_BUTTON, self.OnButton1Button,
> id=wxID_FRAME1FREQ)
>
>     def __init__(self, parent):
>         self._init_ctrls(parent)
>
>     def OnButton1Button(self, event):
>
>         def create(parent):
>             return Frame2(parent)
>         [wxID_FRAME2, wxID_FRAME2FREQ, wxID_FRAME2FREQDISP,
> wxID_FRAME2STATICTEXT1,] = [wx.NewId() for _init_ctrls in range(4)]
>
>         class Frame2:
          ~~~~~~~~~~~~~~~should be class Frame2(wx.Frame):
>             def __init__(self):
>                 #
>                 wx.Frame.__init__(self, id=wxID_FRAME2, name='',
> parent=prt,
>                       pos=wx.Point(400, 179), size=wx.Size(300, 133),
>                       style=wx.DEFAULT_FRAME_STYLE, title='Frame2')
>                 self.SetClientSize(wx.Size(233, 99))
>
>                 self.staticText1 =
> wx.StaticText(id=wxID_FRAME2STATICTEXT1,
>                       label='frequency goes here first',
> name='staticText2', parent=self,
>                       pos=wx.Point(24, 32), size=wx.Size(71, 13),
> style=0)
>
>                 self.freqdisp2 = wx.TextCtrl(id=wxID_FRAME2FREQDISP,
> name='freqdisp2',
>                       parent=self, pos=wx.Point(104, 24),
> size=wx.Size(100, 21),
>                       style=0, value=' ')
>
>                 self.freq = wx.Button(id=wxID_FRAME2FREQ, label='get
> freq', name='freq',
>                       parent=self, pos=wx.Point(24, 56),
> size=wx.Size(184, 23),
>                       style=0)
>                 self.freq.Bind(wx.EVT_BUTTON, self.OnButton2Button,
> id=wxID_FRAME2FREQ)
>
>             def __init__(self, parent):
>                 self._init_ctrls(parent)
>             def OnButton2Button(self, event):
>                 freqdisp.Append('this is it 24HZ!')
>             Show()
               ~~~~~~~~~~~~~~~~~~~~should be create(self).Show()
>
> if __name__ == '__main__':
>     app = wx.PySimpleApp()
>     frame = create(None)
>     frame.Show()
>
>     app.MainLoop()

Hi,
I found two errors in your program.
one is that class Frame2 must be inherited from wx.Frame,
the other is Show() must belong a object.










More information about the Python-list mailing list