我正在尝试实现系统,当用户指向一个对象时,会出现一个文本框,其中包含我尚未实现的某些信息,然后当他们将鼠标移开时消失。我试图通过绑定 < Enter > 和 < Leave > 命令来做到这一点,但是当我运行以下代码时没有任何反应,除了在终端中它说 destroy 需要两个参数,所以我知道它正在调用函数.
from tkinter import *
xhig, yhig = 425,325
bkgnclr = '#070707'
currentmouseoverevent = ''
c = Canvas(master, width=xhig*2, height=yhig*2, bg=bkgnclr, cursor = 'crosshair',)
def mouseovertext(event):
mouseover = "Jack"
currentmouseoverevent = event
c.create_rectangle(bbox=(event.x,event.y, (event.x + 5), (event.y +len(mouseover)*5)),outline="white", fill=bkgnclr, width= len(mouseover))
c.create_text(position=(event.x,event.y),text=mouseover, fill="white", currentmouseoverevent=event)
def closemouseover(x):
c.destroy(currentmouseoverevent)
c.bind("<Enter>", mouseovertext)
c.bind("<Leave>", closemouseover)
destroy 需要什么参数,为什么没有创建矩形?