
Event Handling In Tkinter Python means to bind the keyboard or mouse buttons to the Tkinter and use them to call some functions.
We use bind() function to bind keys and functions to each other.
Here, functions can be in-built or made by the programmer.
Let’s see the code to call the in-built function and self made function using the gui.
Code
# importing tkinter
from tkinter import *
# initializing root
root = Tk()
# width and height variables
can_width = 300
can_height = 200
# setting geometry of gui
root.geometry(f"{can_width}x{can_height}")
# setting title of gui
root.title("Event handling")
# creating a label
Label(root, text="Click anywhere").pack()
# initializing variable
i = 0
# defining a function
def me(event):
global i
Label(root, text=f"You clicked me {i} time").pack()
Label(root, text="Double click to exit screen").pack()
i=i+1
# binding mouse left button to root and calling me function
root.bind("<Button-1>", me)
# binding double click mouse left button to root and calling
# in-built quit function
root.bind("<Double-1>", quit)
# calling mainloop
root.mainloop()
Output
Now, here is the code to call the previous functions using the button.
Code
# importing tkinter
from tkinter import *
# initializing root
root = Tk()
# width and height variables
can_width = 300
can_height = 200
# setting geometry of gui
root.geometry(f"{can_width}x{can_height}")
# setting title of gui
root.title("Event handling")
# creating a button
win = Button(root, text="Click me")
# packing the button to gui to show it on screen
win.pack()
# initializing variable
i = 0
# defining a function
def me(event):
global i
Label(root, text=f"You clicked me {i} time").pack()
Label(root, text="Double click to exit screen").pack()
i=i+1
# binding mouse left button to win and calling me function
win.bind("<Button-1>", me)
# binding double click mouse left button to win and calling
# in-built quit function
win.bind("<Double-1>", quit)
# calling mainloop
root.mainloop()
Output
Also Read:
- You Can Now Run AI Fully Offline on Your Phone — Google’s Gemma 4 Just Changed Everything
What if your smartphone could run a powerful AI assistant without internet, without cloud, and without API costs? That’s now possible. Google recently introduced a… - I Built a 24×7 AI Blogging System for WordPress Using Python (Free) — Full Code Inside
In this article, I will show you how I built a powerful Python-based system that automatically generates and publishes articles to WordPress — completely free… - This Reddit User “Hacked” AI With Simple Tricks… And The Results Are Insane
What if you could get dramatically better answers from AI—without any advanced prompting skills, tools, or coding? A recent Reddit post is going viral for… - One “rm -rf” Command Almost Wiped Out $100 Million Worth of Toy Story 2
In software, a single command can make or break everything. But in the late 1990s, one mistake at Pixar nearly erased months of work—and potentially… - How to Make Money with ChatGPT in 2026: A Real Guide That Still Works
There’s a silent thought many people are carrying right now. It doesn’t always get said out loud, but it’s there: “AI has made everything too…








