Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

easy way to check is wxtextctrl has data

Posted on 2012-08-11
3
Medium Priority
?
489 Views
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'
	else:
	    print'yes'

Open in new window

0
Comment
Question by:dolamitejenkins
  • 2
3 Comments
 
LVL 29

Expert Comment

by:pepr
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)
        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
 
LVL 29

Accepted Solution

by:
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'
	else:
	    print'yes'

Open in new window

0
 

Author Closing Comment

by:dolamitejenkins
ID: 38308692
Thank you
0

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