How do you print out a value from wx.TextCtrl?

1.6k Views Asked by At

I have something like this right now:

import wx

class QuickAddBox(wx.TextCtrl):
    def __init__(self, parent, viewer):
        self.quick_add_text = wx.TextCtrl.__init__(self, parent, -1, '', size=(300,20), style=wx.TE_PROCESS_ENTER)
        self.Bind(wx.EVT_TEXT_ENTER, self.OnPress, self.quick_add_text)

    def OnPress(self, evt):
        print self.quick_add_text.GetValue()

And I want to get the value of the textbox when I click enter. But when I do click enter, I get the following error:

AttributeError: 'NoneType' object has no attribute 'GetValue'

Any advice?

_________________________________________-

Nevermind I solved it by doing the following:

def OnPress(self, evt):
    print self.GetValue()
1

There are 1 best solutions below

2
On

Looks like you're storing the return value of TextCtrl's __init__ (which is None) instead of the actual class instance. Your __init__ should likely look like this:

class QuickAddBox(wx.TextCtrl):
    def __init__(self, parent, viewer):
        self.quick_add_text = wx.TextCtrl(self, parent, -1, '', size=(300,20), style=wx.TE_PROCESS_ENTER)