from tkinter import *
import time
def left(event):
x0, y0, x1, y1 = w.coords(rec)
if x0 > 0:
w.move(rec, -step, 0)
def right(event):
x0, y0, x1, y1 = w.coords(rec)
if x1 < 300:
w.move(rec, +step, 0)
def down(event):
x0, y0, x1, y1 = w.coords(rec)
if y1 < 300:
w.move(rec, 0, +step)
def up(event):
x0, y0, x1, y1 = w.coords(rec)
if y0 > 0:
w.move(rec, 0, -step)
size = 30; step = 10
window = Tk()
window.title('키로 사각형 이동')
w = Canvas(window, width=300, height=300)
w.bind('<Left>', left)
w.bind('<Right>', right)
w.bind('<Up>', up)
w.bind('<Down>', down)
w.focus_set()
w.pack()
rec = w.create_rectangle(150, 200, 150+size, 200+size, fill='blue')
window.mainloop()
처음에 def down을 -step으로 했는데 위로 가길래 down이랑 up을 서로 반대로 했는데
이거 y축에서 +step -step이면 +step해야 위로 가는거 아냐?? 왜 반대로 가?
좌표측이 븅신이겄제 ㅋㅋㅋㅋㅋㅋ