The binding function is used to handle events. We can tie Python’s functions and methods to an event as well as any specific widget.
Example:
from tkinter import *
from tkinter.ttk import *
# creates tkinter window or root window
ws = Tk()
ws.geometry('200x100')
def enter(event):
print('Button-2 pressed at x = % d, y = % d'%(event.x, event.y))
def exit_(event):
print('Button-3 pressed at x = % d, y = % d'%(event.x, event.y))
frame_1 = Frame(ws, height = 100, width = 200)
frame_1.bind('', enter)
frame_1.bind('', exit_)
frame_1.pack()
ws.mainloop()