Tkinter – SimpleDialog
The Tkinter simpledialog module contains classes and functions for creating simple modal dialogs to get a value from the user. It means it is not necessary to receive input in console mode all the time.
Tkinter Functions to receive input in PopUp window as per its official website.
tkinter.simpledialog.askfloat(title, prompt, **kw) tkinter.simpledialog.askinteger(title, prompt, **kw) tkinter.simpledialog.askstring(title, prompt, **kw)
The above three functions provide dialogbox or popup windows that prompt the user to enter a value of the desired type.
Program to receive Integer value in Dialogbox
from tkinter import * import tkinter.simpledialog root = Tk() no = tkinter.simpledialog.askinteger('Admno','Enter Admission No') if type(no)==int: print('Input was an integer number') root.mainloop()
The output of the above code is
In the same way, we can have Tkinter simpledialog box function to receive float values as well as string values. Tkinter messagebox is also there to generate a simple dialog box.
Program to receive a list of numbers using SimpleDialog
There is no such function exists in Tkinter, so we will use askString( ) function to do the needful.
from tkinter import * import tkinter.simpledialog root = Tk() no = tkinter.simpledialog.askstring('List Input','Enter number ') no = no.split() print(no) root.mainloop()
The output of the above code generates an input dialog box like this
as we all are aware of the type of input. thus just converted it into a list and print it.
Recommended Reading: Python List
All these types of dialog boxes can be controlled from the click event of a button and other events.