用python turtle库画正方形_用Python Turtle画一个正方形
你的主要錯誤是這兩行順序錯誤:window.exitonclick() #click the screen to close it
draw_square()
exitonclick(),或mainloop(),或done()應該是最靈活的,針對上述和樣式問題,你的代碼需要重新編寫:import turtle
# to draw a square, or eventually a turtle, you need to do the things below
def draw_square():
""" draw square for turtles """
# to draw a square you want to : move forward, turn right,
# move forward, turn right,move forward turn right
brad = turtle.Turtle()
brad.forward(100) # forward takes a number which is the distance to move
brad.right(90) # turn right
brad.forward(100)
brad.right(90)
brad.forward(100)
brad.right(90)
brad.forward(100)
brad.right(90)
window = turtle.Screen()
# this is the background where the turtle will move
window.bgcolor("red") # the color of the window
draw_square()
window.exitonclick() # click the screen to close it
總結
以上是生活随笔為你收集整理的用python turtle库画正方形_用Python Turtle画一个正方形的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: dataframe 选择输出_使用 Py
- 下一篇: python一个函数调用另一个函数_在P