You want to use a QInputDialog
. This has a bunch of static methods which generate a complete dialog, and return the selected integer when the user clicks OK. This means you don't need to worry about creating a dialog object, adding widgets and buttons, etc.
So you would want to call:
parent_window = self #probably..., depends on your code
minimum_value = 1
maximum_value = 99
default_value = 1
title = "Profile"
message = "Select your user ID"
user_id, ok = QInputDialog.getInt(parent_window, title, message, default_value, minimum_value, maximum_value)
When the QInputDialog
line of code runs, a dialog will be presented to the user. When the user clicks OK or Cancel, the entered user_ID will be placed in user_id
and ok
will be a boolean value that indicates whether the OK button was clicked (True
if the OK button was clicked, False
if the cancel button was clicked)
If you want to place an integer in the message, you could do something like:
message = "Select your user ID. An integer I want you to know about is %d. I hope you find that useful."%my_integer
But that is really a Python string formatting question, which you should research separately. In short, in my example you can display one string. How long, that string is, is up to you (it can be multiple lines, have new line characters, etc)