파이썬 오류 질문드려요. AttributeError: 'Turtle' object has no attribute 'onkeypress'

조회수 1312회
t4=t.Turtle()
t4.shape('turtle')
t4.color('yellow')
t4.up()
t4.goto(30,0)

이렇게 거북이를 만들고

def bng():
    t4.seth(0)
def bnng():
    t4.seth(90)
def bnnng():
    t4.seth(180)
def bnnnng():
    t4.seth(270)
t4.onkeypress(bng,'w')
t4.onkeypress(bnng,'d')
t4.onkeypress(bnnng,'s')
t4.onkeypress(bnnnng,'a')
t.listen()

이게 프로그래밍했는데

Traceback (most recent call last):
  File "C:\Users\82108\OneDrive\바탕 화면\터틀.py", line 55, in <module>
    t4.onkeypress(bng,'w')
AttributeError: 'Turtle' object has no attribute 'onkeypress'

이런 오류가 뜹니다. 어떻게 해결하나요? 제발 알려주세요.

1 답변

  • import turtle as t
    
    t4=t.Turtle() 
    t4.shape('turtle') 
    t4.color('yellow') 
    t4.up() 
    t4.goto(30,0)
    
    def bng(): 
        t4.seth(0) 
    def bnng(): 
        t4.seth(90) 
    def bnnng(): 
        t4.seth(180)
    def bnnnng(): 
        t4.seth(270) 
        t.onkeypress(bng,'w') 
        t.onkeypress(bnng,'d')
        t.onkeypress(bnnng,'s')
        t.onkeypress(bnnnng,'a') 
        t.listen()
    

    이렇게 하면 아마 동작 될거에요. t4는 객체이기에 turtle 객체엔 onkeypress 함수가 없거든요. turtle 클래스에 onkeypress가 있습니다.

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)