-2

Technically, what I am trying to say is that when you run the program and scroll over something IN the program it should show something.

Here's some code to try it on: Like in this case, when you scroll over the buttons it should show what color it is.

from tkinter import *

root = Tk()

one = Button(root, text="One", bg="red", fg="white")
one.pack()
two = Button(root, text="Two", bg="green", fg="black")
two.pack(fill=X)
three = Button(root, text="Three", bg="blue", fg="white")
three.pack(side=LEFT, fill=Y)

root.mainloop()
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Abhi
  • 17
  • 3

1 Answers1

0

I'm getting my answer from here. The Pmw.Balloon class from the Pmw toolkit for Tkinter can help.

This blog post has a pretty good solution.

Here's the code for a tooltip class I took from the blog

from Tkinter import *

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() + 27
    y = y + cy + self.widget.winfo_rooty() +27
    self.tipwindow = tw = Toplevel(self.widget)
    tw.wm_overrideredirect(1)
    tw.wm_geometry("+%d+%d" % (x, y))
    try:
        # For Mac OS
        tw.tk.call("::tk::unsupported::MacWindowStyle",
                   "style", tw._w,
                   "help", "noActivates")
    except TclError:
        pass
    label = Label(tw, text=self.text, justify=LEFT,
                  background="#ffffe0", relief=SOLID, borderwidth=1,
                  font=("tahoma", "8", "normal"))
    label.pack(ipadx=1)

def hidetip(self):
    tw = self.tipwindow
    self.tipwindow = None
    if tw:
        tw.destroy()

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)
Edgecase
  • 673
  • 1
  • 7
  • 23