Learn how to a build a cloud-first strategyRegister Now


easy way to check is wxtextctrl has data

Posted on 2012-08-11
Medium Priority
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
  • 2
LVL 29

Expert Comment

ID: 38284896
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 29

Accepted Solution

pepr earned 2000 total points
ID: 38285309
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

ID: 38308692
Thank you

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
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 if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
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…
Suggested Courses

810 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