
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Binding mouse double click in Tkinter
Let us suppose that for a particular application, we want to bind the mouse double-click so that it performs some event or operation. We can use the bind(‘<Double-Button-1>’, handler) or bind(‘<Double-Button-2>’, handler) methods to bind the mouse Left or Right Buttons with a handler or a callback function.
Example
In this example, we will create an application that contains a button. When we double click the button, it will open a popup window.
#Import required libraries from tkinter import * from tkinter import ttk #Create an instance of tkinter frame win= Tk() #Define the geometry of the window win.geometry("750x250") #Define a function def handler(e): top= Toplevel(win) top.geometry("600x200") Label(top, text= "Hey There!", font= ('Helvetica 15 bold')).pack(pady=30) #Define a Label in Main window Label(win, text= "Double Click to Open the Popup",font=('Helvetica 15 underline')).pack(pady=30) #Create a Button ttk.Button(win, text= "Click", command=lambda:handler).pack(pady=20) #Bind the Double Click with the Handler win.bind('<Double-Button-1>', handler) win.mainloop()
Output
Now, run the above code to display the window.
Double-click the button "Click" to open a popup window.
- Related Questions & Answers
- How to configure default Mouse Double-Click behavior in a Tkinter text widget?
- Binding function in Python Tkinter
- Mouse Position in Python Tkinter
- Store mouse click event coordinates with Matplotlib
- Changing the Mouse Cursor in Tkinter
- Binding an object's method to a click handler in JavaScript
- How to handle a mouse right click event using jQuery?
- Trigger an event IMMEDIATELY on mouse click, not after I let go of the mouse - JavaScript?
- Tkinter binding a function with arguments to a widget
- How to handle a double click event using jQuery?
- How to perform double click on an element in Selenium?
- How to move a Tkinter canvas with Mouse?
- How to change the mouse pointer color in Tkinter?
- Static binding and dynamic binding in Java
- Static binding vs Dynamic binding in C#
Advertisements