-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAnimation in Mouse motion .py
More file actions
36 lines (24 loc) · 940 Bytes
/
Copy pathAnimation in Mouse motion .py
File metadata and controls
36 lines (24 loc) · 940 Bytes
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
32
33
34
35
36
#;====================================================
#; Title: Animation in Mouse Motion
#; Author: @AyemunHossain
#;====================================================
import tkinter as tk
root = tk.Tk()
def animate(event):
position = f"x = {event.x} y = {event.y}"
print(f"{str(event.type)}, Event {position}")
if str(event.type) is "Enter":
canvus.config(bg="red")
elif str(event.type) is "Motion":
canvus.config(bg="green")
elif str(event.type) is "ButtonRelease":
canvus.config(bg="red")
elif str(event.type) is "Leave":
canvus.config(bg="gray")
canvus = tk.Canvas(root,width= 500,height=400,bg="gray")
canvus.pack(anchor = "nw")
canvus.bind("<B1-Motion>",lambda event:animate(event))
canvus.bind("<ButtonRelease-1>",lambda event:animate(event))
canvus.bind("<Enter>",lambda event:animate(event))
canvus.bind("<Leave>",lambda event:animate(event))
root.mainloop()