0% found this document useful (0 votes)
11 views

tooltip program tkiner

The document defines a method to create tooltips for widgets in a graphical user interface using Python. It includes a ToolTip class that manages the display and hiding of tooltip windows when the mouse enters or leaves a widget. The tooltip shows specified text in a small window near the widget.

Uploaded by

coreymurphy613
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

tooltip program tkiner

The document defines a method to create tooltips for widgets in a graphical user interface using Python. It includes a ToolTip class that manages the display and hiding of tooltip windows when the mouse enters or leaves a widget. The tooltip shows specified text in a small window near the widget.

Uploaded by

coreymurphy613
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

def CreateToolTip(self, widget, text):

#self.CreateToolTip(close_button, text="Returns the the Main Menu")


toolTip = ToolTip(widget)
def enter(event):
toolTip.showtip(text)
def leave(event):
toolTip.hidetip()
widget.bind('<Enter>', enter)
widget.bind('<Leave>', leave)

##### Begin ToolTip Class Definition#####


class ToolTip(object):
def __init__(self, widget):
self.widget = widget
self.tipwindow = None
self.id = None
self.x = self.y = 0

def showtip(self, text):


## Display text in tooltip window ##
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()
y = y + cy + self.widget.winfo_rooty() + 70
self.tipwindow = tw = Toplevel(self.widget)
tw.wm_overrideredirect(1)
tw.wm_geometry("+%d+%d" % (x, y))
label = Label(tw, text=self.text, justify=LEFT,
background="#ffffe0", relief=SOLID, borderwidth=1,
font=("tahoma", "10", "normal"))
label.pack(ipadx=1)

def hidetip(self):
tw = self.tipwindow
self.tipwindow = None
if tw:
tw.destroy()
##### End ToolTip Class Definition #####

You might also like