22 Sep turtle.textinput() function in Python
The turtle.textinput() function pops up a dialog window for input of a string. Returns the input string, or None if cancelled.
Syntax: turtle.textinput(title, prompt)
Parameters: title – string (title of the dialog window); prompt – string (text to describe what information to input).
Let us see an example to implement the turtle.textinput() function in Python:
Demo55.py
# turtle.textinput() function in Python
# Code by Studyopedia
import turtle
window = turtle.Screen()
t = turtle.Turtle()
# Get text input from user
name = window.textinput("Name", "What is your name?")
t.write(f"Hello, {name}!", font=("Arial", 16, "normal"))
window.exitonclick()
The following is the output:

In the above code, we followed the below steps:
- Import module: import turtle loads the turtle graphics library.
- Create screen: window = turtle.Screen() opens the drawing window.
- Create turtle: t = turtle.Turtle() creates the turtle you’ll control.
- Prompt for text: name = window.textinput(“Name”, “What is your name?”) shows a modal input box with title “Name” and the prompt. Returns the entered string or None if the user cancels.
- Write greeting: t.write(f”Hello, {name}!”, font=(“Arial”, 16, “normal”)) draws the text at the turtle’s current position using the specified font. It doesn’t move the turtle; if name is None, it will print “Hello, None!”.
- Close on click: window.exitonclick() waits for a mouse click, then closes the window.
If you liked the tutorial, spread the word and share the link and our website, Studyopedia, with others.
For Videos, Join Our YouTube Channel: Join Now
Read More:
- OpenCV Tutorial
- Python Tutorial
- NumPy Tutorial
- Pandas Tutorial
- Matplotlib Tutorial
- Generative AI Tutorial
- LangChain Tutorial
- RAG Tutorial
- Machine Learning Tutorial
- Deep Learning Tutorial
- Ollama Tutorial
- Retrieval Augmented Generation (RAG) Tutorial
- Copilot Tutorial
- Gemini Tutorial
- ChatGPT Tutorial
No Comments