This article covers Tkinter SimpleDialog, which is a sub class of Tkinter.
The SimpleDialog module is used to create dialog boxes to take input from the user in a variety of ways. SimpleDialog allows us to take input of varying datatypes from the user, such as float, string and integer.
The below Tkinter SimpleDialog functions work together with tkinter. A tkinter window is required for these functions to work. If a tkinter window is not present, these functions will create one by default.
SimpleDialog – askinteger
The askinteger() function is used to get an integer from the user. It accepts only int values.
from tkinter.simpledialog import askinteger
root = tk.Tk()
prompt = askinteger("Input", "Input an Integer")
print(prompt)
root.mainloop()

SimpleDialog – askfloat
The askfloat() function is used to get float values from the user. It accepts integer values, but returns them in float format.
from tkinter.simpledialog import askfloat
root = tk.Tk()
prompt = askfloat("Input", "Input an Float")
print(prompt)
root.mainloop()

SimpleDialog – askstring
The askstring() function is used to get a string from the user. You can pass values of any type to it, but it will return them in string format.
from tkinter.simpledialog import askstring
root = tk.Tk()
prompt = askstring("Input", "Input an String")
print(prompt)
root.mainloop()

An interesting side note. If you pass an string value into the float function for instance, it will not throw an exception and terminate the program. A simple error prompt will be shown, and the program will continue as normal.
If you only want to show a simple dialog with only text (no inputs), then take a look at the Tkinter messagebox widget.
This marks the end of the Tkinter SimpleDialog article. Suggestions or contributions for CodersLegacy are more than welcome. Any questions can be asked in the comments section below.
can you limit the lenght of input?
Not that i’m aware of, no. If that’s something important to you however, I suggest you merely make your own Dialog Class. It’s much easier than it looks. It’s just a label, an Entry widget, and two buttons after all. You can easily add a limit in a custom class of your own.
When i do this i get 2 python windows
how do i fix this?
Remove root.mainloop() or something with mainloop in it