【发布时间】:2023-01-27 15:19:33
【问题描述】:
我是 Python 的新手,我刚刚尝试使用 Python Turtle。我正在关注 youtube 上的教程,当我尝试打开 Python Turtle 时,它显示“无响应”并且无法打开页面。 我的鼠标有加载符号,然后它只给我没有响应的消息。
这是我到目前为止编写的代码:
import turtle
WIDTH, HEIGHT = 500, 500
screen = turtle.Screen()
screen.setup(WIDTH, HEIGHT)
screen.title("Turtle Racing")
def get_number_of_turtles():
num_turtles = 0
while True:
num_turtles = input("Enter the number of racers (2-10): ")
if num_turtles.isdigit():
num_turtles = int(num_turtles)
else:
print("Invalid input.")
continue
if 2 <= num_turtles <= 10:
return num_turtles
else:
print("Number not in range 2-10.")
get_number_of_turtles()
有谁知道如何解决这一问题?
【问题讨论】:
-
你是如何运行这个的?从终端?从 IDE?哪个操作系统?请记住,这需要从终端获取输入。如果您从没有终端的设备上运行它,它会显示为不活动。
-
@TimRoberts 我正在使用 Windows 并在 Pycharm 中运行它。 Python turtle 是只有在 cmd 中运行时才有效的东西吗?顺便说一句,我没试过这个
-
您是否在 Pycharm 终端窗口中看到“输入赛车手数量”提示?
-
@TimRoberts 我现在尝试在 cmd 上运行这个文件,这很有效。然而,当我回到 pycharm 并尝试运行这段代码时,我得到了错误:[Errno 2] No such file or directory
-
这似乎是一个新问题的主题!
标签: python turtle-graphics python-turtle