我正在尝试使用模块turtle绘制一个“黄色”星。在Windows OS上运行程序时,它可以正常运行。但是,当我在macOS上运行它时,图形是错误的。 Result on macOS
import turtle
# Setup a screen and a turtle
win = turtle.Screen()
bob = turtle.Turtle()
# set the background color for the flag
win.bgcolor("red")
# Draw a star
# change the turtle color to yellow
bob.color("yellow")
# to center we have to go backward for half of a side length
bob.penup()
bob.back(100)
bob.pendown()
bob.begin_fill()
for i in range(5):
bob.forward(200)
bob.right(144)
bob.end_fill()
win.exitonclick()
答案 0 :(得分:0)
这不是乌龟问题,而是底层tkinter库的问题。当涉及交叉线时,两个操作系统上的填充是不同的。解决方案是绘制星形而不交叉线:
from turtle import Screen, Turtle
win = Screen()
win.bgcolor("red")
bob = Turtle()
bob.color("yellow")
bob.penup()
bob.goto(24.5, 33.1)
bob.pendown()
bob.begin_fill()
for i in range(5):
bob.forward(80)
bob.right(144)
bob.forward(80)
bob.left(72)
bob.end_fill()
bob.hideturtle()
win.exitonclick()
这在两种实现上都应该看起来相同: