0

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?

  • Does this answer your question? [AttributeError: NoneType object has no attribute](https://stackoverflow.com/a/1101765/7414759) – stovfl Jun 11 '20 at 14:32

1 Answers1

1

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:

enter image description here

DaveStSomeWhere
  • 2,475
  • 2
  • 22
  • 19