Prompting for a username and displaying a welcome message
This recipe will prompt the user to enter a name, and when the user clicks the OK
button after entering a name, they are greeted with an alert box with the text Hello
, followed by the name entered by the user.
How to do it...
In this recipe, we will be making use of the following methods:
dialogGetInput()
: This method is used to take input from the userapp.dialogCreateAlert()
: This method is used to greet the userapp.dialogSetPositiveButtonText()
: This method is used to display positive button text and to keep the dialog box visible until the user presses theOK
button
Let's take a look at the following steps:
- Type the following code in the Python script
WelcomeMessage.py
in the current folder:
import android app = android.Android() name = app.dialogGetInput("Enter Your Information", "Name: ").result app.dialogDismiss() app.dialogCreateAlert("Welcome", "Hello %s" % name) app.dialogSetPositiveButtonText('OK') app.dialogShow()
- Copy or push...