Python Forum
[PyGUI] [Solved]Help storing in user input from line edit
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGUI] [Solved]Help storing in user input from line edit
#1
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 :)
Reply
#2
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.
Reply
#3
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] [Solved]Change text color of one line in TextBrowser Extra 2 4,761 Aug-23-2022, 09:11 PM
Last Post: Extra
  Convert combobox user input in to date with tkinter Ame 8 6,656 Jul-01-2020, 09:40 PM
Last Post: Yoriz
  Create an identification code from user input PeroPuri 1 1,870 Apr-11-2020, 11:56 AM
Last Post: Larz60+
  [PyQt] Python PyQt5 - Change label text dynamically based on user Input ppel123 1 13,661 Mar-20-2020, 07:21 AM
Last Post: deanhystad
  PyQt5: How do you set the user input of a line edit to a specific variable? YoshikageKira 17 11,469 Dec-26-2019, 03:18 PM
Last Post: Denni
  [Tkinter] Is there a way to sleep without stopping user input? GalaxyCoyote 2 2,097 Oct-23-2019, 06:23 PM
Last Post: Denni
  [Tkinter] Registering user's drop down menu choice and finding corresponding line in files ShadeLily 2 1,971 Oct-03-2019, 06:28 PM
Last Post: joe_momma
  [Tkinter] help please, checking the user input and outputting the result tomkovladko 3 2,710 Mar-05-2019, 08:58 PM
Last Post: joe_momma
  [PyGUI] Hi All, how to hide/mask user input in PySimpleGUI nmrt 1 14,836 Sep-21-2018, 09:59 AM
Last Post: nmrt
  PyQt4 get text from line edit into label on button push iFunKtion 2 21,713 Feb-27-2017, 12:14 PM
Last Post: iFunKtion

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020