How to have GUI based program wait until user enters acceptable input
-
wrote on 14 Oct 2021, 16:30 last edited by poordev123
I have a text edit in my gui that a user will enter a value into it. If the value is not entered, I want to show a popup message, tell them that it is empty, and then have them re-enter it. Right now what's happening is that the popup message is being displayed, but then the user does not have the chance to change the value, the program just continues running and crashes.
I have a 'connect' push button which is the trigger for all of this that is called pb_ip_connection
self.ui.pb_ip_connection.connect(self.get_ip) @staticmethod def get_ip(): ip_addr = self.ui.text_edit_ip.toPlainText() if ip_addr == "": ctypes.windll.user32.MessageBoxW(0, "Enter an IP address", "ERROR", 1) # something has to go here to make the program go back and look for the new IP address that the user is going to enter before moving forward
I am also aware that I can do something along the lines of
while True: ip_addr = self.ui.text_edit_ip.toPlainText() if ip_addr == "": ctypes.windll.user32.MessageBoxW(0, "Enter an IP address", "ERROR", 1 continue else: break
That would work if the user was entering an input, but since this is gui driven it just shows the popup over and over again and does not give the user a chance to change anything
-
Use a QLineEdit instead a QTextEdit, connect to signal QLineEdit::textChanged() and check the input in the connected slot. Or/And put a QValidator on it so the user can not enter e.g. characters.
-
I have a text edit in my gui that a user will enter a value into it. If the value is not entered, I want to show a popup message, tell them that it is empty, and then have them re-enter it. Right now what's happening is that the popup message is being displayed, but then the user does not have the chance to change the value, the program just continues running and crashes.
I have a 'connect' push button which is the trigger for all of this that is called pb_ip_connection
self.ui.pb_ip_connection.connect(self.get_ip) @staticmethod def get_ip(): ip_addr = self.ui.text_edit_ip.toPlainText() if ip_addr == "": ctypes.windll.user32.MessageBoxW(0, "Enter an IP address", "ERROR", 1) # something has to go here to make the program go back and look for the new IP address that the user is going to enter before moving forward
I am also aware that I can do something along the lines of
while True: ip_addr = self.ui.text_edit_ip.toPlainText() if ip_addr == "": ctypes.windll.user32.MessageBoxW(0, "Enter an IP address", "ERROR", 1 continue else: break
That would work if the user was entering an input, but since this is gui driven it just shows the popup over and over again and does not give the user a chance to change anything
wrote on 14 Oct 2021, 17:29 last edited by@poordev123
As @Christian-Ehrlicher says, except that you may rather want to use signal QLineEdit::editingFinished().Completely separate from your question, it seems such a shame that you use
ctypes.windll.user32.MessageBoxW()
to display a message box. If you are going to use Qt why use anything like that? Anyway, QMessageBox Class. -
@poordev123
As @Christian-Ehrlicher says, except that you may rather want to use signal QLineEdit::editingFinished().Completely separate from your question, it seems such a shame that you use
ctypes.windll.user32.MessageBoxW()
to display a message box. If you are going to use Qt why use anything like that? Anyway, QMessageBox Class. -
@poordev123
As @Christian-Ehrlicher says, except that you may rather want to use signal QLineEdit::editingFinished().Completely separate from your question, it seems such a shame that you use
ctypes.windll.user32.MessageBoxW()
to display a message box. If you are going to use Qt why use anything like that? Anyway, QMessageBox Class.wrote on 14 Oct 2021, 17:52 last edited by@JonB @JoeCFD Okay I just switched to using QMessageBox then, I had not thought about running this on different operating systems. Thank you for the tip.
@Christian-Ehrlicher thank you for the textChanged input. I am going to try to implement that
1/5