-
-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Labels
✨ EnhancementNew feature or requestNew feature or request🔥 WIPWork in progress...Work in progress...🟧 Medium Priority
Description
Feature Description
我在为控件添加鼠标悬停事件时,发现 tk 原生的 bind 方法被重写了,重写后的 bind 不能正确处理鼠标的 <Enter>
和 <Leave>
事件
测试代码如下
root = maliang.Tk((300, 300))
cv = maliang.Canvas(root)
cv.place(width=300, height=300)
text = maliang.Button(cv, (100, 100), text="Hello, world!")
text.bind("<Enter>", lambda e: print("鼠标进入"))
text.bind("<Leave>", lambda e: print("鼠标离开"))
text.bind("<Motion>", lambda e: print("鼠标移动", end=''))
root.mainloop()
其中 <Enter>
和 <Leave>
事件无法正常执行,而 <Motion>
事件(以及其他 Button 事件)可以正常执行。
在咨询 ai 后得知:对于 canvas 绘制的图形,可以使用 tag_bind
方法控制哪些图形元素响应事件,其函数原型为
tag_bind(self, tagOrId, sequence=None, func=None, add=None)
其中 tagOrId 需要填入 标签名
或 元素ID
,对于 maliang 而言,疑似只能支持 canvas.create_xxx
这类能返回 int 编号的图形,不能支持 virtual.Widget
类控件,因此请求添加相应的支持
Possible Implementation
对于这个问题,解决方案应该还挺多样的,除了扩展 canvas.tag_bind
方法之外,也可以考虑封装一下 TkappType.getint
方法,或者直接让 maliang 的 bind 可以支持 <Enter>
和 <Leave>
事件。当然最好的情况是 maliang 本来就可以实现这个功能只是我操作有问题
Contact Details
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
✨ EnhancementNew feature or requestNew feature or request🔥 WIPWork in progress...Work in progress...🟧 Medium Priority