Python Tutorial for Beginners

What is Binding Functions in Python Tkinter?

Understanding Binding Functions in Python Tkinter

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.


from tkinter import *

from tkinter.ttk import *

# creates tkinter window or root window

ws = Tk()


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_) 


Did you find this article helpful?