How to get an Entry box within a Messagebox in Tkinter?

Published December 30, 2021

You may wish to create a dialog box that displays as a modal dialog, and then an entry box with buttons that will enable you to manage and show your own conversation messages within it. This tutorial will show you how to create an entry box inside the Tkinter MessageBox.

 

How to get an EntryBox within a MessageBox in Tkinter?

There are numerous methods and built-in functions in the Tkinter Messagebox library that we can utilize to show our Messagebox. In this scenario, we'd want to show a Messagebox that will gather user input from the Entry widget. We'll utilize the askstring library from simpledialog to do this. This library allows us to show a window that accepts two arguments: the window's title and the input title for the Entry widget

There are numerous methods and built-in functions in the Tkinter Messagebox library that we can utilize to show our Messagebox. In this scenario, we'd want to show a Messagebox that will gather user input from the Entry widget. We'll utilize the askstring library from simpledialog to do this. This library allows us to show a window that accepts two arguments: the window's title and the input title for the Entry widget.

 

Example

Have a look at the example below

# Import the required library

from tkinter import *

from tkinter.simpledialog import askstring

from tkinter.messagebox import showinfo

# Create an instance of tkinter frame and window

win=Tk()

win.geometry("500x300")

name = askstring('Name', 'What is your Favourite Programming Language?')

showinfo('Hello!', 'Welcome to, {}'.format(name))

win.mainloop()

 

 

The code above shows an Entrybox inside a Messagebox, inviting the user to input their preferred programming language's name. After the user chooses their preferred language, it continues to welcome them in their preferred programming language.

Output

Tkinter Messagebox with Entry field

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

556 Views