Reputation:
I want to create a simple example with Pmw Balloon, in which a tooltip is shown if the cursor is on a widget (e.g. button):
from tkinter import *
import Pmw
root = Tk()
Pmw.initialise(root)
# Create some random widget
button = Button(root, text = " This is a Test", pady = 30).pack(pady = 10)
# create ballon object and bind it to the widget
balloon = Pmw.Balloon(root)
balloon.bind(button,"Text for the tool tip")
mainloop()
However, i am getting an error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-23-1972bd06d4e6> in <module>
10 # create ballon object and bind it to the widget
11 balloon = Pmw.Balloon(root)
---> 12 balloon.bind(button,"Text of the tool tip")
13
14 mainloop()
~/anaconda3/lib/python3.7/site-packages/Pmw/Pmw_2_0_1/lib/PmwBalloon.py in bind(self, widget, balloonHelp, statusHelp)
75 if statusHelp is None:
76 statusHelp = balloonHelp
---> 77 enterId = widget.bind('<Enter>',
78 lambda event, self = self, w = widget,
79 sHelp = statusHelp, bHelp = balloonHelp:
AttributeError: 'NoneType' object has no attribute 'bind'
Does someone of you know what went wrong and how to fix it?
Upvotes: 1
Views: 1221
Reputation: 2540
Tkinter doesn't allow you to chain the pack with the button definition because pack
doesn't return the button object.
Just break it into two lines and your code executes successfully.
Try:
# Create some random widget
button = Button(root, text=" This is a Test", pady=30)
button.pack(pady=10)
Result:
Upvotes: 2