#! /bin/env python # coding: utf8 import Tkinter as tk import re class HoverInfo(tk.Menu): def __init__(self, parent, text, statusbar, command=None): self._com = command self.statusbar = statusbar tk.Menu.__init__(self,parent, tearoff=0) if not isinstance(text, str): raise TypeError('Trying to initialise a Hover Menu with a non string type: ' + text.__class__.__name__) toktext=re.split('\n', text) for t in toktext: self.add_command(label = t) self.text = text self._displayed=False self.master.bind("",self.Display ) self.master.bind("",self.Remove ) def __del__(self): self.master.unbind("") self.master.unbind("") def Display(self,event): if not self._displayed: self._displayed=True self.statusbar.set(self.text) #self.post(event.x_root, event.y_root) if self._com != None: self.master.unbind_all("") self.master.bind_all("", self.Click) def Remove(self, event): if self._displayed: self.statusbar.set("") self._displayed=False self.unpost() if self._com != None: self.unbind_all("") def Click(self, event): self._com()