首页 > 解决方案 > Python Turtle 图形框不显示

问题描述

这是我的代码,当我运行此代码时:

from turtle import Turtle

def draw_square():
    window = turtle.Screen()
    window.bgcolor("red")


    brad = turtle.Turtle()
    brad.shape("turtle")
    brad.color("yellow")
    brad.speed(2)
    turtle.forward(100)
    turtle.right(90)
    turtle.forward(100)
    turtle.right(90)
    turtle.forward(100)
    turtle.right(90)
    turtle.forward(100)
    turtle.right(90)

什么都没有发生,只是 shell 出现说 RESTART 就像你在图片中看到的那样。请帮帮我!

错误描述

标签: pythonturtle-graphics

解决方案


请写下代码而不是链接屏幕截图。让事情变得更容易:)

代码在函数定义中,但您没有在任何地方调用该函数。尝试在程序结束时调用它:

from turtle import Turtle

def draw_square(): # function definition
    window = turtle.Screen()
    ...
    ...
    brad.right(90)

draw_square() # call the function

推荐阅读