-1

I'm working on a silly page for my friends, however when the code askes for user input I am incapable of entering any data. How can I possibly fix this?

# import the turtle module
import turtle as trtl
troll = trtl.Turtle()
clr = input("give a color pls: ")
bgcolor(clr)
wn = trtl.Screen()
wn.mainloop()
toolic
62.9k21 gold badges81 silver badges130 bronze badges
asked Apr 9, 2025 at 2:44
3
  • what page? Web page? Turtle is not for web pages. Commented Apr 9, 2025 at 12:18
  • 2
    did you run code in console to see error message? Commented Apr 9, 2025 at 12:18
  • input() gets its data from the terminal where the script is running. Commented May 7, 2025 at 15:07

2 Answers 2

1

Without seeing the rest of the code, I think the most likely problem is doing all of this before you have the screen initialized. After all, if the screen has not been created yet, where would you expect the input to appear? Here is how I would change it:

import turtle as trtl
troll = trtl.Turtle() 
# Create the screen first
wn = trtl.Screen()
clr = input("give a color pls: ")
# properly use bgcolor as a function from turtle, not a standalone function
wn.bgcolor(clr)
wn.mainloop()
answered Apr 9, 2025 at 3:09
Sign up to request clarification or add additional context in comments.

Comments

0

Based on @KRoscoe45's answer but with a bit of error handling :

import turtle as trtl
troll = trtl.Turtle() 
color_list=["blue","red","pink","black","white"]
wn = trtl.Screen()
clr = input("give a color pls: ")
while not crl in color_list :
 input(f"Color must be part of this list :\n{color_list}.\nPlease reenter one:\t")
wn.bgcolor(clr)
wn.mainloop()

This would handle error caused if the user dosn't enter a color that is understandable by the turtle module by reasking for a color until the answer is part of color_list.

answered May 7, 2025 at 14:37

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.