(widget, text)
| 968 | |
| 969 | |
| 970 | def add_tooltip(widget, text): |
| 971 | tipwindow = None |
| 972 | |
| 973 | def showtip(event): |
| 974 | """Display text in tooltip window.""" |
| 975 | nonlocal tipwindow |
| 976 | if tipwindow or not text: |
| 977 | return |
| 978 | x, y, _, _ = widget.bbox("insert") |
| 979 | x = x + widget.winfo_rootx() + widget.winfo_width() |
| 980 | y = y + widget.winfo_rooty() |
| 981 | tipwindow = tk.Toplevel(widget) |
| 982 | tipwindow.overrideredirect(1) |
| 983 | tipwindow.geometry(f"+{x}+{y}") |
| 984 | try: # For Mac OS |
| 985 | tipwindow.tk.call("::tk::unsupported::MacWindowStyle", |
| 986 | "style", tipwindow._w, |
| 987 | "help", "noActivates") |
| 988 | except tk.TclError: |
| 989 | pass |
| 990 | label = tk.Label(tipwindow, text=text, justify=tk.LEFT, |
| 991 | relief=tk.SOLID, borderwidth=1) |
| 992 | label.pack(ipadx=1) |
| 993 | |
| 994 | def hidetip(event): |
| 995 | nonlocal tipwindow |
| 996 | if tipwindow: |
| 997 | tipwindow.destroy() |
| 998 | tipwindow = None |
| 999 | |
| 1000 | widget.bind("<Enter>", showtip) |
| 1001 | widget.bind("<Leave>", hidetip) |
| 1002 | |
| 1003 | |
| 1004 | @backend_tools._register_tool_class(FigureCanvasTk) |
no outgoing calls
no test coverage detected
searching dependent graphs…