New submission from Jason Yang <[email protected]>:
Button no response when clicked if mouse move into tooltip and tooltip
destroyed for Python 3.9.9/3.10.1 and tkinter 8.6.12
You can check it by moving mouse into button, then move to tooltip after it
shown, then click button and you won't get response for button clicked, but
"Leave". It is OK for lower version of Python/tkinter.
```python
import sys
from datetime import datetime
import tkinter as tk
class Tooltip(object):
"""
create a tooltip for a given widget
"""
def __init__(self, widget, text='widget info'):
self.waittime = 500 # miliseconds
self.widget = widget
self.text = text
self.widget.bind("<Enter>", self.enter)
self.widget.bind("<Leave>", self.leave)
self.widget.bind("<ButtonPress>", self.leave)
self.id = None
self.top = None
def enter(self, event=None):
print(now(), "Enter")
self.schedule()
def leave(self, event=None):
print(now(), "Leave")
self.unschedule()
self.hidetip()
def schedule(self):
self.unschedule()
self.id = self.widget.after(self.waittime, self.showtip)
def unschedule(self):
id = self.id
self.id = None
if id:
self.widget.after_cancel(id)
def showtip(self, event=None):
x = y = 0
x, y, cx, cy = self.widget.bbox("insert")
x += self.widget.winfo_rootx() + self.widget.winfo_width()//2
y += self.widget.winfo_rooty() + self.widget.winfo_height()//2
self.top = tk.Toplevel(self.widget)
self.top.wm_overrideredirect(True)
self.top.wm_geometry("+%d+%d" % (x, y))
label = tk.Label(self.top, text=self.text, bd=1, font=font,
relief='solid')
label.pack(ipadx=1)
def hidetip(self):
top = self.top
self.top = None
if top:
top.destroy()
def now():
return datetime.now().strftime("%H:%M:%S")
print(f"Python version : {sys.version.split(' ')[0]}")
print(f"tkinter version: {tk.Tcl().eval('info patchlevel')}")
font = ("Courier New", 40)
root = tk.Tk()
button = tk.Button(root, text="button", font=font,
command=lambda:print(now(), 'Button clicked'))
button.pack(padx=10, pady=5)
tooltip = Tooltip(button, 'This is button 1')
root.mainloop()
```
```python
d:\>python test.py
Python version : 3.10.1
tkinter version: 8.6.12
18:21:52 Enter (Mouse to button)
18:21:54 Leave (mouse to tooltip)
18:21:55 Leave (button clicked get no response)
18:21:57 Leave (button clicked get no response)
18:21:58 Leave (button clicked get no response)
d:\>python test.py
Python version : 3.9.9
tkinter version: 8.6.12
18:22:51 Enter (Mouse to button)
18:22:54 Leave (mouse to tooltip)
18:22:55 Leave (button clicked get no response)
18:22:56 Leave (button clicked get no response)
18:22:57 Leave (button clicked get no response)
d:\>python test.py
Python version : 3.8.10
tkinter version: 8.6.9
18:23:22 Enter (Mouse to button)
18:23:23 Leave (mouse to tooltip)
18:23:23 Enter (mouse stay, and it will repeat `Enter and Leave` again and
again)
18:23:24 Leave
...
18:23:28 Enter
18:23:28 Leave
18:23:28 Button clicked (button clicked get response)
18:23:31 Leave
18:23:31 Button clicked (button clicked get response)
18:23:32 Leave
```
Platform - WIN10
----------
components: Tkinter
messages: 409188
nosy: Jason990420
priority: normal
severity: normal
status: open
title: Button clicked failed when mouse hover tooltip and tooltip destroyed
type: crash
versions: Python 3.10, Python 3.8, Python 3.9
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue46180>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com