python中的海龟图形无法正常工作
我试图执行《如何像计算机科学家一样思考》一书第四章中的以下代码 但是,海龟对象似乎没有绘制倾斜的正方形python中的海龟图形无法正常工作,python,turtle-graphics,Python,Turtle Graphics,我试图执行《如何像计算机科学家一样思考》一书第四章中的以下代码 但是,海龟对象似乎没有绘制倾斜的正方形 import turtle def draw_multicolor_square(t, sz): """Make turtle t draw a multi-color square of sz.""" for i in ["red", "purple", "hotpink", "blue"]: t.color(i) t.forward(sz)
import turtle
def draw_multicolor_square(t, sz):
"""Make turtle t draw a multi-color square of sz."""
for i in ["red", "purple", "hotpink", "blue"]:
t.color(i)
t.forward(sz)
t.left(90)
wn = turtle.Screen() # Set up the window and its attributes
wn.bgcolor("lightgreen")
tess = turtle.Turtle() # Create tess and set some attributes
tess.pensize(3)
size = 20 # Size of the smallest square
for i in range(15):
draw_multicolor_square(tess, size)
size = size + 10 # Increase the size for next time
tess.forward(10) # Move tess along a little
tess.right(18) # and give her some turn
wn.mainloop()
我希望有几个正方形,但它只画了3个没有坡度的正方形。水蟒上的海龟可能有一些问题。我在另一个网站上找到了这篇文章: 使用turtle.bye()调用turtle.done(),并使用IPython控制台的内联或自动后端(首选项>IPython控制台>图形>图形后端)。例如:
如果你只看到三个正方形,这意味着你的海龟图形没有显示斜线,只显示水平和垂直。这已经出现过好几次了,例如:
答案似乎总是“这是一个图形驱动程序问题”。一旦图形卡驱动程序问题得到纠正,事情就会按预期开始工作。我不能说得更具体了,因为这取决于您的系统设置。除了有令人恶心的颜色外,您的代码在我的计算机上运行良好。您使用的是什么版本的python<代码>导入系统;打印(sys.version)3.5.5 | Anaconda,Inc.|(默认值,2018年5月13日,21:27:04)[GCC 7.2.0]该链接似乎处理在Anaconda下再次运行代码的问题,而不是成功运行的程序中缺少图形元素的问题。