Entry
How do I bind a Pmw.Balloon tooltip and another event to the same widget?
Jul 1st, 2008 22:20
jack seo, Mickel Grönroos,
I think, I solved this one myself. What you need to do is put the
widget in a Frame, then you can bind the Pmw.Balloon to the Frame and
do the other binding to the original widget which is placed within the
frame. Just make sure the original widget uses all space available in
the frame.
Here's an example of how you can create a toolbar button that is
graphically raised AND that displays a tooltip (with Pmw.Balloon) when
the mouse pointer is hovering over it (a la Internet Explorer):
import Tkinter
import Pmw
## Two functions that we will need for changing the graphical
## appearence of a button created below.
def raised(event=None):
button.config(relief=Tkinter.RAISED)
def flat(event=None):
button.config(relief=Tkinter.FLAT)
## Create the main window and associate it with Pmw
root = Tkinter.Tk()
Pmw.initialise(root)
## Create a frame just for binding the tooltip to it later
frame = Tkinter.Frame(root)
frame.pack()
## Create a button, i.e. the widget you really want to have.
## Place the button in the frame.
button = Tkinter.Button(frame,
text="Exit",
borderwidth=1,
command=root.destroy,
relief=Tkinter.FLAT)
button.pack(fill=Tkinter.BOTH, expand=1, padx=0, pady=0)
## Create the tooltip and bind it to the frame
balloon = Pmw.Balloon(root)
balloon.bind(frame, "Click here to exit")
## Create the other binding to the actual button
## In this case, the button is raised when the mouse
## pointer enters its space and flattened when the mouse
## pointer leaves
button.bind("<Enter>", raised)
button.bind("<Leave>", flat)
## Action!
root.mainloop()
http://topweddingguide.blogspot.com
http://homenaturalremedies.blogspot.com/