python - 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 就像你在图片中看到的那样。请帮帮我!
解决方案
请写下代码而不是链接屏幕截图。让事情变得更容易:)
代码在函数定义中,但您没有在任何地方调用该函数。尝试在程序结束时调用它:
from turtle import Turtle
def draw_square(): # function definition
window = turtle.Screen()
...
...
brad.right(90)
draw_square() # call the function
推荐阅读
- matlab - 创建一个 MATLAB 函数来确定客户在购买后应支付的零钱金额
- c - 如何监视 C 模块中的静态数据?
- c - 如何修复“错误:控制到达非无效函数的结尾”?
- gitlab - 在 gitlab 中将 cucumber.options 作为环境变量传递
- mysql - 计算 MySQL 中多个外部表的引用总数
- python - 获取当前时间之前的最近时间,该时间可被 5 整除
- apostrophe-cms - 从爬虫中排除特定区域
- swift - “RTCSdpTypeAnswer”和“RTCSdpTypePrAnswer”有什么区别?
- virtualbox - 如何解决 VirtualBox 桥接适配器问题?
- python - 如何使一定长度的单词翻转?