51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
|
import tkinter
|
||
|
import webbrowser
|
||
|
|
||
|
|
||
|
# TODO: http://effbot.org/zone/tkinter-text-hyperlink.htm ?
|
||
|
|
||
|
class ToolTip(object):
|
||
|
# https://stackoverflow.com/a/56749167/733214
|
||
|
def __init__(self, widget):
|
||
|
self.widget = widget
|
||
|
self.tipwindow = None
|
||
|
self.id = None
|
||
|
self.x = self.y = 0
|
||
|
|
||
|
def showtip(self, text):
|
||
|
self.text = text
|
||
|
if self.tipwindow or not self.text:
|
||
|
return()
|
||
|
x, y, cx, cy = self.widget.bbox("insert")
|
||
|
x = x + self.widget.winfo_rootx() + 57
|
||
|
y = y + cy + self.widget.winfo_rooty() +27
|
||
|
self.tipwindow = tw = tkinter.Toplevel(self.widget)
|
||
|
tw.wm_overrideredirect(1)
|
||
|
tw.wm_geometry('+{0}+{1}'.format(x, y))
|
||
|
label = tkinter.Label(tw, text = self.text, justify = tkinter.LEFT,
|
||
|
background = '#ffffe0', relief = tkinter.SOLID, borderwidth = 1,
|
||
|
font = ('Tahoma', 8, 'normal'))
|
||
|
label.pack(ipadx = 1)
|
||
|
return()
|
||
|
|
||
|
def hidetip(self):
|
||
|
tw = self.tipwindow
|
||
|
self.tipwindow = None
|
||
|
if tw:
|
||
|
tw.destroy()
|
||
|
return()
|
||
|
|
||
|
|
||
|
def CreateToolTip(widget, text):
|
||
|
toolTip = ToolTip(widget)
|
||
|
|
||
|
def enter(event):
|
||
|
toolTip.showtip(text)
|
||
|
|
||
|
def leave(event):
|
||
|
toolTip.hidetip()
|
||
|
|
||
|
widget.bind('<Enter>', enter)
|
||
|
widget.bind('<Leave>', leave)
|
||
|
return()
|