-
-
Notifications
You must be signed in to change notification settings - Fork 6
Description
The line self.show_duration = int(show_duration * 1000) causes a problem when a string is passed instead of a float or int (I assume this happens with self.delay = int(delay * 1000) too). If a string is passed instead of 20 * 1000 = 20000 it outputs 20 except 1000 times. This causes a tkinter.TclError: Bad Argument when passed to self.tw.after
I wanted to fix this error in a pull request myself and claim the credit for the fix, but I don't use GitHub and I'm a SUPER new coder and I have no idea how to make a pull request despite trying for a while.
For clarification I am using python 3.12 and TkToolTip Version 1.2.0 as per PIP pip install TkToolTip - Requirement already satisfied: TkToolTip in c:\users\[user]\appdata\local\programs\python\python312\lib\site-packages (1.2.0)
The fix is basically to add a check to type check to ensure delay and show_duration are of a supported type, raising an error if not. Please find below the error traceback, the original code then the fixed code. This won't be the full code, just the relevant lines. Just be warned its probably not the best, but I try!
Exception in Tkinter callback
Traceback (most recent call last):
File "c:\Users\[user]\AppData\Local\Programs\Python\Python312\Lib\tkinter\__init__.py", line 1968, in __call__
return self.func(*args)
^^^^^^^^^^^^^^^^
File "c:\Users\[user]\AppData\Local\Programs\Python\Python312\Lib\tkinter\__init__.py", line 862, in callit
func(*args)
File "c:\Users\[user]\AppData\Local\Programs\Python\Python312\Lib\site-packages\TkToolTip\TkToolTip.py", line 50, in enter
self.id_duration = self.tw.after(self.show_duration, self.leave)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\[user]\AppData\Local\Programs\Python\Python312\Lib\tkinter\__init__.py", line 874, in after
return self.tk.call('after', ms, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_tkinter.TclError: bad argument "20202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020": must be cancel, idle, info, or an integer import tkinter as tk
class ToolTip(object):
def __init__(self,
widget,
relief: str | tuple | None = None,
borderwidth: int = 1,
background : str | tuple | None = None,
text : str | tuple | None = None,
delay: float = 1.0,
show_duration: float = 10.0,
font: tuple | None = None,
text_color: str | tuple | None = None,
justify: str = 'left',
**kwargs: any):
self.widget = widget
self.text = text
self.delay = int(delay * 1000)
self.show_duration = int(show_duration * 1000)
self.font = font
...class ToolTip(object):
def __init__(self,
widget,
relief: str | tuple | None = None,
borderwidth: int = 1,
background : str | tuple | None = None,
text : str | tuple | None = None,
delay: float = 1.0,
show_duration: float = 10.0,
font: tuple | None = None,
text_color: str | tuple | None = None,
justify: str = 'left',
**kwargs: any):
error_types = (int, float)
if not all(isinstance(inputs, error_types) for
inputs in (delay, show_duration)):
if not isinstance(delay, error_types):
error_cause = ("delay", delay)
else:
error_cause = ("show_duration", show_duration)
raise TypeError(f"Please ensure {error_cause[0]}: ({error_cause[1]})is of type int or float")
self.widget = widget
self.text = text
self.delay = int(delay * 1000)
self.show_duration = int(show_duration * 1000)
self.font = font
...