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
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.