diff --git a/coretk/coretk/coretoolbar.py b/coretk/coretk/coretoolbar.py index 83debab5..69379aa0 100644 --- a/coretk/coretk/coretoolbar.py +++ b/coretk/coretk/coretoolbar.py @@ -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() diff --git a/coretk/coretk/tooltip.py b/coretk/coretk/tooltip.py index e69de29b..226b0ed8 100644 --- a/coretk/coretk/tooltip.py +++ b/coretk/coretk/tooltip.py @@ -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("", self.enter) + self.widget.bind("", 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()