Link to home
Start Free TrialLog in
Avatar of Dolamite Jenkins
Dolamite JenkinsFlag for United States of America

asked on

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

Avatar of pepr
pepr

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:
User generated image
ASKER CERTIFIED SOLUTION
Avatar of pepr
pepr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dolamite Jenkins

ASKER

Thank you