프로그램
[파이썬] 터틀 클릭이벤트(클릭한 곳에 원그리기)
오디세이99
2022. 10. 1. 20:49
728x90
반응형
turtle에서 화면 click 한 곳에 원을 그리는 코드입니다.
event 처리하는 방법을 알 수 있습니다.
import turtle
def leftClick(x,y): # 클릭 함수. 이때 클릭 좌표 x, y가 넘어옴
turtle.pencolor("red")
turtle.pensize(4)
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.circle(50) # 반지름 50으로 원그리기
turtle.shape("turtle")
turtle.title('draw')
turtle.onscreenclick(leftClick) # conscreenclick 이벤트에서 선언한 함수 Call
turtle.done()
728x90
반응형