Python Forum

Full Version: [Solved]Help storing in user input from line edit
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I have a Line Edit in my PyQt5 GUI and I'm wondering how I can take the input the user types in and store it into a python variable once the user is done typing (Once the user is no longer on that edit line).


This is the line edit chunk of my GUI code:
 self.NameInput = QtWidgets.QLineEdit(self.centralwidget)
        self.NameInput.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.NameInput.setText("")
        self.NameInput.setObjectName("NameInput")
I've been looking at some tutorials, but they either don't work or are hard to follow.
So if anyone can help me understand how to take in the user's input that would be great.

Thanks in advance.

Some background info (that may/may not help):
This is for my login screen which takes in a Name and a Password. Once the user has entered all that they hit a Log in button. Then it will go through some of my python code to ensure everything's valid then it will go to the main menu. (I already have a working terminal version of this and I hope to have a nice working gui for it :)
Are you trying to get the code when the control loses focus (user is no longer on that line)? To do that you can bind a function to the "editingFinished()" signal. But you don't need to do that for your login screen. You don't care what is typed in the screen until the user presses the login button. You need to bind a function to the clicked() signal of the button, and in that function call self.NameInput.text() to get the text that was typed into the NameInput QLineEdit.
(May-12-2022, 12:11 PM)deanhystad Wrote: [ -> ]Are you trying to get the code when the control loses focus (user is no longer on that line)? To do that you can bind a function to the "editingFinished()" signal. But you don't need to do that for your login screen. You don't care what is typed in the screen until the user presses the login button. You need to bind a function to the clicked() signal of the button, and in that function call self.NameInput.text() to get the text that was typed into the NameInput QLineEdit.

Thanks. That helped. I got it to work now.