Input text for a GUI with tkinter

This is all you need to do to create a function to ask something to the user with python and tkinter:

import tkinter as tk
from tkinter import simpledialog

def input_text(
    title="Title",
    prompt="Question",
    feedback="ok"):

    tk.Tk().withdraw()
    name = simpledialog.askstring(title, prompt)
    print(feedback.format(name))

if __name__ == "__main__":
    input_text(
        "Question",
        "What is your name?",
        feedback="So your name is {}!")

Subscribe to the newsletter for updates
Tkinter templates
My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts