2.2 Write a program that uses input to prompt a user for their name and then welcomes them. Note that input will pop up a dialog box. Enter Sarah in the pop-up box when you are prompted so your output will match the desired output.
Answers
Python simple GUI program that uses input to prompt a user for their name and then welcomes them.
Language Used : Python Programming (GUI - Tkinter)
Program :
import tkinter as tk
from tkinter import simpledialog
from tkinter import messagebox
root = tk.Tk()
root.withdraw()
username = simpledialog.askstring(title="Test",prompt="What's your Name?:")
#printing the statement on shell
print("Hello",username,"!")
#printing the statement on a message box
messagebox.showinfo("Greetings", "Hello "+str(username)+"!")
Input :
A pop-up window opens, asking for your name. You can see that in the attachments given below
Output :
On shell :
Hello Sarah!
On Message box :
See the attachments given below.
Explanation :
- All you need to do is, to import the libraries simpledialog and messagebox from tkinter.
- Then, use the function askstring() from simpledialog to get a pop-up asking for your name.
- Once you input your name, you can print it directly on the shell, or you can use showinfo() from messagebox, to greet using pop-up.
Note : I have added the attachments of the interpretation and the execution of programs with their outputs. Take a look!
Quick Tip : In python, you must and should follow Indentation. Following the indentation property in any programming language will help you in quickly analysing the code, if an error occurs.
Learn more :
- About GUI.
brainly.in/question/16402094
- Sailent features of python.
brainly.in/question/12206981
![](https://hi-static.z-dn.net/files/d71/d98722c33a3001a49858517f10d75a3f.jpg)
![](https://hi-static.z-dn.net/files/df1/b7af948dd8d84174ec6f4ff8f5ddd766.jpg)
![](https://hi-static.z-dn.net/files/d80/aa288936d42c502e4bd76cdbc34b9c8c.jpg)
![](https://hi-static.z-dn.net/files/dae/e93ab30dfe7eeecf5f6fd1ef7fda553e.jpg)