Python 如何临时解除tkinter.Text中事件的绑定?

Python 如何临时解除tkinter.Text中事件的绑定?,python,tkinter,tkinter-text,Python,Tkinter,Tkinter Text,我无法在tkinter.Text小部件中禁用'事件。为什么在本例中unbind()不起作用 from tkinter import * def on_modify(event): print('Modified - this should never happen') root = Tk() root.bind('<Escape>', lambda e: root.quit()) text = Text(root) mod_id = text.bind('<&l

我无法在tkinter.Text小部件中禁用
'
事件。为什么在本例中unbind()不起作用

from tkinter import *


def on_modify(event):
    print('Modified - this should never happen')


root = Tk()
root.bind('<Escape>', lambda e: root.quit())
text = Text(root)
mod_id = text.bind('<<Modified>>', on_modify)

# test - how to temporarily disable Modified event?
text.unbind('<<Modified>>', mod_id)
# text.unbind_all('<<Modified>>')
text.insert(END, 'test')
mod_id = text.bind('<<Modified>>', on_modify)

text.pack()
root.mainloop()
从tkinter导入*
def on_modify(事件):
打印('已修改-这永远不会发生')
root=Tk()
root.bind(“”,lambda e:root.quit())
text=文本(根)
mod_id=text.bind(“”,on_modify)
#测试-如何临时禁用修改的事件?
text.unbind(“”,mod_id)
#文本。全部解除绑定(“”)
text.insert(结束“测试”)
mod_id=text.bind(“”,on_modify)
text.pack()
root.mainloop()

您是否尝试使用
.after
在主循环有机会更新绑定后安排插入?或者您可以在
tkinter.text
中插入
测试“
后添加
text.update()