python退出mainloop_python - 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中。 提前致谢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值