티스토리 뷰
self.canvas.bind("<MouseWheel>", self.on_mouse_wheel) # Windows용
def on_mouse_wheel(self, event):
if event.delta > 0:
self.zoom_level *= 1.1
else:
self.zoom_level *= 0.9
if self.zoom_level < 0.1:
self.zoom_level = 0.1
elif self.zoom_level > 20.0:
self.zoom_level = 20.0
self.update_canvas()
원래 위에 처럼 구현돼있었더라면
아래 처럼 구현해야 윈도우, 리눅스 둘다 휠이벤트가 동작한다.
# 윈도우: <MouseWheel>
# 리눅스: <Button-4> (wheel up), <Button-5> (wheel down)
self.canvas.bind("<MouseWheel>", self.on_mouse_wheel) # Windows용
self.canvas.bind("<Button-4>", self.on_mouse_wheel) # Linux용
self.canvas.bind("<Button-5>", self.on_mouse_wheel) # Linux용
def on_mouse_wheel(self, event):
# Windows의 경우: event.delta 가 +120(휠 위), -120(휠 아래) 식으로 들어옴
# Linux의 경우: event.num == 4(휠 위), 5(휠 아래)
# 1) 휠 위 스크롤?
if (event.delta > 0) or (event.num == 4):
self.zoom_level *= 1.1
# 2) 휠 아래 스크롤?
elif (event.delta < 0) or (event.num == 5):
self.zoom_level *= 0.9
# 최소/최대 줌 제한
if self.zoom_level < 0.1:
self.zoom_level = 0.1
elif self.zoom_level > 20.0:
self.zoom_level = 20.0
self.update_canvas()'Python' 카테고리의 다른 글
| conda environment도 도커의 Dockerfile처럼 기술할 수 있다! (0) | 2025.10.30 |
|---|---|
| python 프로젝트에서 환경 변수 쉽게 관리하기(gpt-5-high-fast 작성) (3) | 2025.08.09 |
| imgdiet 개발 중 주저리 주저리 #2 python decorator 실사용예 (0) | 2025.02.12 |
| imgdiet 개발 중 주저리 주저리 #1 (1) | 2025.02.06 |
| 명령어 한 줄로 anaconda/miniconda/conda 아묻따 모든 env 삭제 (1) | 2025.01.31 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 파이참
- 자료구조
- 가장 긴 증가하는 부분 수열
- 백트래킹
- FairMOT
- 백준
- Lowest Common Ancestor
- 문제집
- 위상 정렬 알고리즘
- LCA
- C++ Deploy
- 백준 11437
- 순열
- 단축키
- cosine
- 조합
- PyCharm
- 백준 11053
- MOT
- 인공지능을 위한 선형대수
- 백준 1766
- 이분탐색
- ㅂ
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
글 보관함
