- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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.
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()
Now, run the above code to display the window.
Double-click the button "Click" to open a popup window.
- 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
- How to handle a mouse right click event using jQuery?
- 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 vs Dynamic binding in C#
- Static binding and dynamic binding in Java