Tkinter Event unbind
The method to unbind the obj is as follows.
obj.unbind("<xxx>") # <xxx>is the binding method
Tkinter Event unbind Example#1
This is a tkinter button program with a checkbox bind/unbind below the tkinter button. if this checkbox is checked, it is equivalent to bind and the Python Shell will list the string Welcome to apidemos.com
when the tkinter button is clicked. If this checkbox is unchecked, it is equivalent to no bind, and Python Shell does not generate any action when the tkinter button is clicked.
from tkinter import *
def buttonClicked(event): # Button Button Event Handler
print("Welcome to apidemos.com")
# The passed object onoff is the btn object
def toggle(onoff): # Toggle binding
if var.get(): # If True binds
onoff.bind("<Button-1>",buttonClicked)
cbtn.config(text="Binded")
else: # If False does unbind
onoff.unbind("<Button-1>")
cbtn.config(text="UnBinded")
root = Tk()
root.title("apidemos.com")
root.geometry("300x180")
btn = Button(root,text="tkinter")
btn.pack(anchor=W,padx=10,pady=10)
var = BooleanVar()
# var.set(True)
cbtn = Checkbutton(root,text="bind/unbind",variable=var,
command=lambda:toggle(btn))
cbtn.pack(anchor=W,padx=10)
# var.set(True)
root.mainloop()
Output:
When the button is bound to a checkbox, clicking the tkinter button prints the apidemos.com
string in the Python Shell window.