easy way to check is wxtextctrl has data

I'm looking for a simple way to just check to see if my textctrl has data entered using wypython and the wxTextctrl... I'm trying something like this but it doesn't work


license_no = self.quantity.GetValue()
	if license_no !='':
	    print 'No'
	else:
	    print'yes'

Open in new window

dolamitejenkinsAsked:
Who is Participating?
 
peprConnect With a Mentor Commented:
Possibly add the .strip() to your if condition to eliminate the case when whitespace is in the control:
    license_no = self.quantity.GetValue()
	if license_no.strip() != '': 
	    print 'No'
	else:
	    print'yes'

Open in new window

0
 
peprCommented:
I guess you make some minor mistake. Basically, it should work. Try the following self standing example:
import wx

class MainWindow(wx.Frame):
    def __init__(self, parent, title):

        # No fancy window, just to show it works...
        wx.Frame.__init__(self, parent, title=title, size=(300, 100))

        # The controls. Push the button for testing
        self.quantity = wx.TextCtrl(self)
        self.button = wx.Button(self, wx.ID_OK, 'Test it')

        # Events.
        self.Bind(wx.EVT_BUTTON, self.OnTest, self.button)

        # Use the sizer for the layout.
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.quantity)
        self.sizer.Add(self.button)

        # Set the sizer and show the window.
        self.SetSizer(self.sizer)
        self.Show()


    def OnTest(self, e):
        # Test the control value.
        license_no = self.quantity.GetValue()
        if license_no != '':
            msg = 'not empty: ' + repr(license_no)
        else:
            msg = 'empty.'

        # The message box to show the result of testing.
        dlg = wx.MessageDialog(self, 'The control value is ' + msg,
                                     'Test of the control', wx.OK)
        dlg.ShowModal() # Shows it
        dlg.Destroy() # finally destroy it when finished.


app = wx.App(False)
frame = MainWindow(None, 'TextControl test')
app.MainLoop()

Open in new window

I can see the following on my computer:
Testing the wx.TextCtrl value.
0
 
dolamitejenkinsAuthor Commented:
Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.