diff --git a/porcupine/utils.py b/porcupine/utils.py index 8be70341d..c176332cd 100644 --- a/porcupine/utils.py +++ b/porcupine/utils.py @@ -167,7 +167,6 @@ def show(self) -> None: if self.got_mouse: self.destroy_tipwindow() tipwindow = type(self).tipwindow = tkinter.Toplevel() - tipwindow.geometry(f"+{self.mousex + 10}+{self.mousey - 10}") tipwindow.bind("", self.destroy_tipwindow, add=True) tipwindow.overrideredirect(True) @@ -176,6 +175,15 @@ def show(self) -> None: # the label will have light text on a light background or # dark text on a dark background on some systems. tkinter.Label(tipwindow, text=self.text, border=3, fg="black", bg="white").pack() + tipwindow.update_idletasks() + screen_width = tipwindow.winfo_screenwidth() + to_end = screen_width - self.mousex + tip_width = tipwindow.winfo_width() + if to_end >= tip_width / 2: + offset = int(tip_width / 2) + else: + offset = int(tip_width - to_end) + tipwindow.geometry(f"+{self.mousex - offset}+{self.mousey - 30}") def set_tooltip(widget: tkinter.Widget, text: str) -> None: