from tkinter import *
def paint(event):
x1, y1=(event.x-1), (event.y+1)
x2, y2 = (event.x-1), (event.y+1)
canvas.create_line(x1, y1, x2, y2)
window=Tk()
canvas=Canvas(window)
canvas.pack()
canvas.bind("<B1-Press>", paint)
canvas.bind("<B1-Release>", paint)
canvas.Button(window, fill="yellow") #중간에 색을 바꾸는 button 객체를 생성하였다.
window.mainloop()
코드는 이렇고
C:\Users\user\Pictures\pythonProject\venv\Scripts\python.exe C:/Users/user/Pictures/pythonProject/main.py
Traceback (most recent call last):
File "C:\Users\user\Pictures\pythonProject\main.py", line 12, in <module>
canvas.bind("<B1-Press>", paint)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1392, in bind
return self._bind(('bind', self._w), sequence, func, add)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1346, in _bind
self.tk.call(what + (sequence, cmd))
_tkinter.TclError: bad event type or keysym "Press"
Process finished with exit code 1
와 같이 오류가 뜹니다.
어떤 부분이 잘못되었는지 이유를 모르겠어서 질문을 남깁니다.
고수분들의 도움이 필요합니다.
감사합니다.
tkinter에 event가 없는데
B1-Press가 짤렸네
Button-1 으로 쓰셈
그리고 paint 함수도 x1, y1이 x2, y2랑 같은데 선이 그려지긴 함?
아 그것도 있네요 수정했습니다 감사합니다.