Computer Science, asked by chetanreddykonda333, 8 months ago

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.And final out put is hello sarha

Answers

Answered by poojan
0

Python 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.

        https://brainly.in/question/16402094

  • Sailent features of python.

        https://brainly.in/question/12206981

Hope it helped you! Cheers!

Attachments:
Similar questions