[wxPython-users] how do I reference the value of a text control

Michael Barron barronmo at gmail.com
Thu Nov 15 13:14:23 PST 2007


Andrea:

Thanks for the help; GetTopLevelParent() works very nicely.

Mike

On Nov 14, 2007 3:47 PM, Andrea Gavana <andrea.gavana at gmail.com> wrote:
> Hi Mike,
>
> On Nov 14, 2007 9:41 PM, Michael Barron wrote:
> > Sorry about such basic question but I've been reading/searching for
> > the answer since lunch and haven't found anything I understand.  I'm
> > trying to lookup up a name in a database.  Here is the code so far:
> >
> > class screen1(wx.Panel):
> >     def __init__(self, parent, id):
> >         wx.Panel.__init__(self, parent, id)
> >
> >         # A button
> >         self.button =wx.Button(self, 10, "Search", wx.Point(200, 200))
> >         wx.EVT_BUTTON(self, 10, self.OnClick)
> >         # the edit control - one line version.
> >         self.lblname = wx.StaticText(self, -1, "Enter the first
> > letters of the last name:",wx.Point(40,60))
> >         self.editname = wx.TextCtrl(self, 20, "", wx.Point(300, 60),
> > wx.Size(140,-1))
> >
> >
> >     def OnClick(self,event):
> >         Repository(frame, -1, namefrag=self.editname.GetValue())
>
> The main problem is here: inside the OnClick method, the method itself
> doesn't know anything about a variable called "frame", which is not in
> the method scope. If your frame is the top level parent of the
> button/textctrl, you might try something like:
>
>      def OnClick(self,event):
>          frame = wx.GetTopLevelParent(self)
>          Repository(frame, -1, namefrag=self.editname.GetValue())
>
>
> > The error I'm getting is 'global name frame not defined'.  Obviously I
> > thought I had defined it in main().  Also, I'm not sure how to
> > reference the value in a control.  Is 'self.editname.GetValue()'
> > correct?
>
> Yes, it's correct. You may also try to use a more Pythonic way to
> retrieve the value (whatever "pythonic" means), using the wx.TextCtrl
> attributes instead of the function:
>
> namefrag = self.editname.Value
>
> Which, if I didn't make stupi mistakes, is equivalent to:
>
> namefrag = self.editname.GetValue()
>
> HTH.
>
> Andrea.
>
> "Imagination Is The Only Weapon In The War Against Reality."
> http://xoomer.alice.it/infinity77/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
>
>




More information about the wxpython-users mailing list