List of All Tkinter Events

Tkinter is a Python library used to create GUI applications. It provides various events that serve as a bridge between user interactions and application logic, making applications interactive and functional.

Here is a comprehensive list of common Tkinter events used to handle user interactions ?

Mouse Events

  • <Button> − Triggered when any mouse button is pressed. Use <Button-1> for left, <Button-2> for middle, <Button-3> for right click.
  • <ButtonRelease> − Triggered when a mouse button is released after being pressed.
  • <Motion> − Tracks mouse pointer movement within a widget area.
  • <Enter> − Triggered when mouse pointer enters a widget's area (mouse hover).
  • <Leave> − Triggered when mouse pointer leaves a widget's area.

Keyboard Events

  • <KeyPress> − Triggered when any key is pressed down. Use <Key> as shorthand.
  • <KeyRelease> − Triggered when a pressed key is released.

Focus Events

  • <FocusIn> − Triggered when a widget gains keyboard focus.
  • <FocusOut> − Triggered when a widget loses keyboard focus.

Window Events

  • <Configure> − Triggered when a widget's size, position, or other properties change.
  • <Destroy> − Triggered when a widget is being destroyed or removed.
  • <Map> − Triggered when a widget becomes visible on screen.
  • <Unmap> − Triggered when a widget becomes hidden from screen.
  • <Expose> − Triggered when a widget or part of it becomes visible after being covered.
  • <Visibility> − Triggered when the visibility state of a widget changes.

Example: Mouse Click Event

This example demonstrates the <Button-1> event to display text when the left mouse button is clicked ?

# Import the Required libraries
from tkinter import *

# Create an instance of tkinter frame or window
win = Tk()

# Set the size of the window
win.geometry("700x350")
win.title("Tkinter Mouse Click Event")

# Define a function to display the message
def display_text(event):
    label.config(text="Code never lies, comments sometimes do", 
                font=('Helvetica', 17, 'bold'))

# Create a label widget to add some text
label = Label(win, text="Click anywhere in the window!", 
              font=('Arial', 12))
label.pack(pady=50)

# Bind the Mouse button event
win.bind('<Button-1>', display_text)
win.mainloop()

Example: Keyboard Event

This example shows how to handle keyboard events ?

from tkinter import *

win = Tk()
win.geometry("400x200")
win.title("Keyboard Event Example")

def key_pressed(event):
    label.config(text=f"You pressed: {event.char}")

label = Label(win, text="Press any key!", font=('Arial', 14))
label.pack(pady=50)

# Bind keyboard event to the window
win.bind('<KeyPress>', key_pressed)
win.focus_set()  # Set focus to window to capture key events

win.mainloop()

Event Binding Syntax

Events are bound to widgets using the bind() method ?

widget.bind("<event>", callback_function)

The callback function receives an event object containing information about the triggered event, such as mouse coordinates, key pressed, or widget references.

Conclusion

Tkinter events enable interactive GUI applications by responding to user actions like mouse clicks, keyboard input, and window changes. Understanding these events is essential for creating responsive and user-friendly applications.

Updated on: 2026-03-25T22:18:14+05:30

15K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements