首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AttributeError:'_Screen‘对象没有属性'mainloop’

AttributeError:'_Screen‘对象没有属性'mainloop’
EN

Stack Overflow用户
提问于 2015-06-14 16:50:38
回答 1查看 7.1K关注 0票数 2

我正在设计一个简单的Python程序,它使用Turtle图形模块在屏幕上用箭头键画线。

代码语言:javascript
复制
import turtle

turtle.setup(400,500)                # Determine the window size
wn = turtle.Screen()                 # Get a reference to the window
wn.title("Handling keypresses!")     # Change the window title
wn.bgcolor("lightgreen")             # Set the background color
tess = turtle.Turtle()               # Create our favorite turtle

# The next four functions are our "event handlers".
def h1():
   tess.forward(30)

def h2():
   tess.left(45)

def h3():
   tess.right(45)

def h4():
    wn.bye()                        # Close down the turtle window

# These lines "wire up" keypresses to the handlers we've defined.
wn.onkey(h1, "Up")
wn.onkey(h2, "Left")
wn.onkey(h3, "Right")
wn.onkey(h4, "q")

# Now we need to tell the window to start listening for events,
# If any of the keys that we're monitoring is pressed, its
# handler will be called.
wn.listen()
wn.mainloop()

当我尝试执行它时,将返回以下错误。

代码语言:javascript
复制
Traceback (most recent call last):
  File "C:\Users\Noah Huber-Feely\Desktop\PEN_Programming\Python\etchy_sketch1.py", line 32, in <module>
    wn.mainloop()
AttributeError: '_Screen' object has no attribute 'mainloop'

我使用Python2.7,以前没有遇到过海龟图形方面的问题。直到现在,我才开始用关键的投入来解决这个问题。

在网上搜索,我只找到了与我目前正在经历的不同问题和模块有关的文章。

如果你需要更多的信息,请告诉我。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-14 16:54:31

它仍然是turtle.mainloop(),而不是wn.mainloop()

我怀疑这是因为您可以制作多个屏幕,所以仍然让turtle模块管理所有屏幕是有意义的,而不是试图让多个主循环协同工作。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30832015

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档