我想用Pmw Balloon创建一个简单的例子,在这个例子中,如果光标在一个部件上(例如按钮),就会显示一个工具提示。
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()
然而,我得到一个错误。
---------------------------------------------------------------------------
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'
你们有人知道是什么地方出了问题以及如何解决吗?