Skip to content

Commit a52ee4b

Browse files
committed
Fix #9
Put after_cancel in try/except block
1 parent 32b53fb commit a52ee4b

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

tkfilebrowser/tooltip.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,14 @@ def __init__(self, tree, delay=1500, **kwargs):
101101
self.current_item = None
102102

103103
self.tree.bind('<Motion>', self._on_motion)
104-
self.tree.bind('<Leave>', lambda e: self.tree.after_cancel(self._timer_id))
104+
self.tree.bind('<Leave>', self._on_leave)
105+
106+
def _on_leave(self, event):
107+
try:
108+
self.tree.after_cancel(self._timer_id)
109+
except ValueError:
110+
# nothing to cancel
111+
pass
105112

106113
def add_tooltip(self, item, text):
107114
"""Add a tooltip with given text to the item."""
@@ -116,7 +123,11 @@ def _on_motion(self, event):
116123
self.tooltip.withdraw()
117124
self.current_item = None
118125
else:
119-
self.tree.after_cancel(self._timer_id)
126+
try:
127+
self.tree.after_cancel(self._timer_id)
128+
except ValueError:
129+
# nothing to cancel
130+
pass
120131
self._timer_id = self.tree.after(self.delay, self.display_tooltip)
121132

122133
def display_tooltip(self):

0 commit comments

Comments
 (0)