add tool tip class to draw tool tip box for the buttons

This commit is contained in:
Huy Pham 2019-09-27 15:28:51 -07:00
parent 5ce340b8b0
commit a1af60688e
2 changed files with 41 additions and 0 deletions

View file

@ -3,6 +3,8 @@ import tkinter as tk
from coretk.images import Images
# from coretk.tooltip import CreateToolTip
class CoreToolbar(object):
"""
@ -267,6 +269,7 @@ class CoreToolbar(object):
command=lambda: self.draw_network_layer_options(network_layer_button),
)
network_layer_button.pack(side=tk.TOP, pady=1)
# network_layer_btt = CreateToolTip(network_layer_button, "Network-layer virtual nodes")
def pick_hub(self, main_button):
self.link_layer_option_menu.destroy()

View file

@ -0,0 +1,38 @@
import tkinter as tk
class CreateToolTip(object):
"""
Create tool tip for a given widget
"""
def __init__(self, widget, text="widget info"):
self.widget = widget
self.text = text
self.widget.bind("<Enter>", self.enter)
self.widget.bind("<Leave>", self.close)
self.tw = None
def enter(self, event=None):
x = 0
y = 0
x, y, cx, cy = self.widget.bbox("insert")
x += self.widget.winfo_rootx()
y += self.widget.winfo_rooty() + 32
self.tw = tk.Toplevel(self.widget)
self.tw.wm_overrideredirect(True)
self.tw.wm_geometry("+%d+%d" % (x, y))
label = tk.Label(
self.tw,
text=self.text,
justify=tk.LEFT,
background="yellow",
relief="solid",
borderwidth=1,
)
label.pack(ipadx=1)
def close(self, event=None):
if self.tw:
self.tw.destroy()