import tkinter as tk
from tkinter import messagebox
from PIL import Image,ImageTk
root=tk.Tk()
root.geometry('960x480+200+100')
root.title('button')
canvas=tk.Canvas(root,highlightthickness=0)
canvas.place(width=960,height=480)
# bg=tk.PhotoImage(file='myw.png')
bg=ImageTk.PhotoImage(Image.open('view2.jpg'))
canvas.create_image(300,300,image=bg)
r1=canvas.create_rectangle(380,350,580,400,outline='black')
r2=canvas.create_rectangle(380+3,350+3,580-3,400-3,outline='black',width=2)
t=canvas.create_text(480,375,text='click',font=('楷体',20,'bold'),fill='green')
canvas.bind('<Button-1>',lambda event:bind_1(event))
canvas.bind('<Button-3>',lambda event:bind_3(event))
canvas.bind('<Motion>',lambda event:bind_2(event))
def bind_1(event):
print(event)
if 380<=event.x<=580 and 350<=event.y<=400:
print('hello')
def bind_2(event):
print(event)
if 380<=event.x<=580 and 350<=event.y<=400:
canvas.itemconfig(r1,outline='white')
canvas.itemconfig(r2,outline='white')
canvas.itemconfig(t,fill='white')
else:
canvas.itemconfig(r1, outline='black')
canvas.itemconfig(r2, outline='black')
canvas.itemconfig(t, fill='green')
def bind_3(event):
print('hello')
tk.messagebox.showinfo('helo','you are right')
root.mainloop()