easy way to check is wxtextctrl has data

Posted on 2012-08-11
Last Modified: 2012-08-18
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'

Open in new window

Question by:dolamitejenkins
    LVL 28

    Expert Comment

    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)
            # Set the sizer and show the window.
        def OnTest(self, e):
            # Test the control value.
            license_no = self.quantity.GetValue()
            if license_no != '':
                msg = 'not empty: ' + repr(license_no)
                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')

    Open in new window

    I can see the following on my computer:
    Testing the wx.TextCtrl value.
    LVL 28

    Accepted Solution

    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'

    Open in new window


    Author Closing Comment

    Thank you

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    The really strange introduction Once upon a time there were individuals who intentionally put the grass seeds to the soil with anticipation of solving their nutrition problems. Or they maybe only played with seeds and noticed what happened... Som…
    Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
    Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
    Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now