1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python中mainloop什么意思_Python Turtle mainloop()用法

python中mainloop什么意思_Python Turtle mainloop()用法

时间:2020-03-31 08:54:39

相关推荐

python中mainloop什么意思_Python Turtle mainloop()用法

我有一个online tutorial的以下代码来学习基于事件的编程,方法是在点击鼠标时使停止灯改变状态。这里是我的代码的全部:Python Turtle mainloop()用法

import turtle

turtle.setup(400,500)

wn = turtle.Screen()

wn.title("Tess becomes a traffic light!")

wn.bgcolor("lightgreen")

tess = turtle.Turtle()

def draw_housing():

tess.pensize(3)

tess.color("black","darkgrey")

tess.begin_fill()

tess.forward(80)

tess.left(90)

tess.forward(200)

tess.circle(40, 180)

tess.forward(200)

tess.left(90)

tess.end_fill()

draw_housing()

tess.penup()

tess.forward(40)

tess.left(90)

tess.forward(40)

tess.shape("circle")

tess.shapesize(3)

tess.fillcolor("green")

state_num = 0

def nextFSMstate():

global state_num

if state_num == 0:

tess.forward(70)

tess.fillcolor("orange")

state_num = 1

elif state_num == 1:

tess.forward(70)

tess.fillcolor("red")

state_num = 2

else:

tess.back(140)

tess.fillcolor("green")

state_num = 0

wn.onkey(nextFSMstate, "space")

wn.listen()

turtle.mainloop()

# example says wn.mainloop() but I get error. This works though

在本教程中,他们使用:

wn.mainloop()

但我得到的错误:

File "stopLights.py", line 51, in

wn.mainloop()

AttributeError: '_Screen' object has no attribute 'mainloop'

并有能力使用

turtle.mainloop()

为什么区别?我在Ubuntu中使用Python 2.7;该示例在PyScripter中。提前致谢。

-07-07

DDauS

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。