日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python退出mainloop_python - Python Turtle mainloop()的用法 - 堆栈内存溢出

發布時間:2023/12/19 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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中。 提前致謝。

總結

以上是生活随笔為你收集整理的python退出mainloop_python - Python Turtle mainloop()的用法 - 堆栈内存溢出的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。