From 8983a69c3e56347782c84ad32fa091eb6441458c Mon Sep 17 00:00:00 2001 From: Rick Lawson Date: Fri, 13 Oct 2023 17:50:19 -0400 Subject: [PATCH] Tooltips go off-screen #1224 center tooltip unless tip would go off the screen and then use what screen space is available --- porcupine/utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/porcupine/utils.py b/porcupine/utils.py index cc58a63aa..ce99867d5 100644 --- a/porcupine/utils.py +++ b/porcupine/utils.py @@ -176,7 +176,14 @@ def show(self) -> None: # 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() - tipwindow.geometry(f"+{self.mousex - tipwindow.winfo_width()}+{self.mousey - 30}") + 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: