Tkinter Canvas 将“<Configure>”事件绑定到项目

Tkinter Canvas bind '<Configure>' event to item

我是不是漏掉了什么?我以为我做了类似下面的例子的事情。 但我既没有找到我希望的脚本,也没有在网上找到任何东西。 基本上我想将 Configure 事件绑定到一个项目。是不是像错误提示的那样可能?

资源:Canvas and tag_bind

import tkinter as tk

def do_something(event=None):
    print('something')
def stupid_workaround():
    if cnvs.coords(lbl) != lbl_coords:
        do_something()
        cnvs.coords(lbl, *lbl_coords)
    
    cnvs.after(200,stupid_workaround)

root = tk.Tk()
cnvs = tk. Canvas(root,highlightthickness=0)
lbl = cnvs.create_text(0,0, text='this is an exampel', anchor='nw')
lbl_coords = cnvs.coords(lbl)
btn = tk.Button(root, text='change coords', command=lambda:cnvs.coords(lbl,10,10))
btn.pack()
stupid_workaround()
#cnvs.bind(lbl, '<Configure>', do_something) #throws no error
#cnvs.tag_bind(lbl, '<Configure>', do_something) #throws error

cnvs.pack()
root.mainloop()

_tkinter.TclError: requested illegal events; only key, button, motion, enter, leave, and virtual events may be used

如错误所述,您无法绑定到 <Configure> 事件,这根本不是一个选项。该事件仅对小部件有效,对 canvas.

上绘制的项目无效