python - AttributeError: '_Screen' object has no attribute 'mainloop' -
i'm designing simple python program uses turtle graphics module draw lines on screen arrow keys.
import turtle turtle.setup(400,500) # determine window size wn = turtle.screen() # reference window wn.title("handling keypresses!") # change window title wn.bgcolor("lightgreen") # set background color tess = turtle.turtle() # create our favorite turtle # next 4 functions our "event handlers". def h1(): tess.forward(30) def h2(): tess.left(45) def h3(): tess.right(45) def h4(): wn.bye() # close down turtle window # these lines "wire up" keypresses handlers we've defined. wn.onkey(h1, "up") wn.onkey(h2, "left") wn.onkey(h3, "right") wn.onkey(h4, "q") # need tell window start listening events, # if of keys we're monitoring pressed, # handler called. wn.listen() wn.mainloop()
when try execute it, following error returned.
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'
i'm using python 2.7 , have had no trouble turtle graphics before. have begun working key input problem has occurred.
searching on web, found articles different issues , modules 1 experiencing.
let me know if need more information. thanks!
it's still turtle.mainloop()
, not wn.mainloop()
.
i suspect reason since can make multiple screens, makes sense still have turtle
module manage of screens instead of trying potentially make multiple mainloops work together.
Comments
Post a Comment