인프런 커뮤니티 질문&답변
파이썬 turtle에서 함수 동시에 사용
작성
·
299
0
파이썬 공부중인 학생이에요. turtle 그래픽에서 하나의 터틀을 움직이게 되면 움직이고 있던 다른 터틀이 계속 멈추게 됩니다. 어떡해야 두 거북이를 모두 움직이게 할 수 있을까요? 코드는 아래에 적을게요.
import turtle as t
import random as r
바늘=t.Turtle()
물고기1=t.Turtle()
물고기2=t.Turtle()
쓰레기1=t.Turtle()
쓰레기2=t.Turtle()
바늘.shape('arrow')
물고기1.shape('turtle')
물고기1.color('red','red')
물고기2.color('green','green')
물고기2.shape('turtle')
쓰레기1.shape('circle')
쓰레기2.shape('circle')
바늘.speed(3)
def 속도1():
s=3
바늘.speed(3)
def 속도2():
s=6
바늘.speed(6)
def 속도3():
s=0
바늘.speed(0)
def goleft():
m,n = 바늘.pos()
바늘.goto (m-20, n)
def goright():
m,n = 바늘.pos()
바늘.goto (m+20, n)
def 던지기():
바늘.pendown()
keep = 1
while keep == 1 :
바늘.fd(20)
m,n = 바늘.pos()
## if 바늘.distance(q,w) <= '30' :
## keep = 0
## 물고기1킾=0
## 바늘.goto(0,470)
if n <= -500 :
keep = 0
바늘.penup()
바늘.sety(470)
def 물고기1함수() :
물고기1.showturtle()
물고기1킾 = 1
물고기1.goto(-500,r.randint(-450,100))
while 물고기1킾 == 1 :
물고기1.fd(1)
q,w = 물고기1.pos()
if q >= 500 :
물고기1.setx(-500)
#초기 세팅
바늘.hideturtle()
물고기1.hideturtle()
물고기2.hideturtle()
쓰레기1.hideturtle()
쓰레기2.hideturtle()
바늘.penup()
바늘.goto(0,470) ##바꿔야됨(낚시대에서 시작, 마우스로 누른곳에 일자로 선 그으며 가서 수직낙하)
바늘.rt(90)
바늘.showturtle()
물고기1.penup()
물고기2.penup()
쓰레기1.penup()
쓰레기2.penup()
t.setup(500,500)
t.onkeypress(goleft, "Left")
t.onkeypress(goright, "Right")
t.onkeypress(던지기, "Return")
t.onkeypress(속도1, "1")
t.onkeypress(속도2, "2")
t.onkeypress(속도3, "3")
t.onkeypress(물고기1함수, "space")
t.listen()
답변




