Check whether a QLineEdit is empty or not

Heads up! You've already completed this tutorial.

Deebalaji asked

I am Newbie to Python and PyQt5.

Just I want to know, How to create a Class/Module to check whether the QLineEdit is empty or not ? and how to import this Module in another Programme/File?

You don't need a class/module to check something as simple as that. PyQt5 Widgets all have their own methods which can be used to get the current state of the widgets. On a QLineEdit you can get the current contents using .text()

Since in Python an empty string "" is falsey and any content is truthy you can just use that value for your conditional, e.g.

python
if lineedit.text():
     # do something if there is content in the line edit.

Hope that helps!

1:1 Coaching & Tutoring for your Python GUIs project
Martin Fitzpatrick Python GUIs Coaching & Training
60 mins ($195) More info

1:1 Python GUIs Coaching & Training

Comprehensive code reviewBugfixes & improvements • Maintainability advice and architecture improvements • Design and usability assessment • Suggestions and tips to expand your knowledgePackaging and distribution help for Windows, Mac & Linux • Find out more.

Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

Check whether a QLineEdit is empty or not was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt.