From 13712bb23669a1658dbdc80ae488939c470f48e6 Mon Sep 17 00:00:00 2001 From: Neuffexx Date: Wed, 4 Oct 2023 15:25:42 +0300 Subject: [PATCH] - Added timer to tooltips, once it runs out tooltip will be destroyed --- ProjectFiles/DisplayKeys-IS.py | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/ProjectFiles/DisplayKeys-IS.py b/ProjectFiles/DisplayKeys-IS.py index 6b55ef1..aa2aa8e 100644 --- a/ProjectFiles/DisplayKeys-IS.py +++ b/ProjectFiles/DisplayKeys-IS.py @@ -728,23 +728,31 @@ def __init__(self, parent: tk.Frame, widget_id: str, label_text: str = None, lab self.b_tooltip = DisplayKeys_Tooltip(self.button, button_tooltip) -# A Tooltip that can be assigned to any of the DisplayKeys_Composite_Widget sub widgets +# A custom Tooltip class based on tk.Toplevel class DisplayKeys_Tooltip: """ A Tooltip that can be assigned to any of the DisplayKeys_Composite_Widget sub widgets + + This tooltip will be stored within the actual Composite Widget, and will keep reference + to the widget that will trigger it. + :param parent: Widget that the Tooltip is Bound to. :param text: The Tooltip text to show. :param justify: The Relative Alignment of Text to itself when broken into a new line. :param anchor: The Alignment of Text in general Relative to the Tooltips Widget Space + :param lifetime: How long the Tooltip should exist for while hovering over its Parent, in seconds. """ def __init__(self, parent: tk.Label | tk.Entry | tk.Spinbox | tk.Button | ttk.Combobox, text: str, justify: Literal["left", "center", "right"] = "center", - anchor: Literal["nw", "n", "ne", "w", "center", "e", "sw", "s", "se"] = "center"): + anchor: Literal["nw", "n", "ne", "w", "center", "e", "sw", "s", "se"] = "center", + lifetime: int = 5): self.parent = parent self.text = text - self.tooltip = None self.text_justification = justify self.text_anchor = anchor + self.tooltip = None + self.tooltip_lifetime = lifetime * 1000 + self.tooltip_lifetime_id = None self.parent.bind("", self.show_tooltip) self.parent.bind("", self.hide_tooltip) self.parent.bind("