带Pmw气球的Tkinter工具提示无法使用。

问题描述 投票:0回答:1

我想用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'

你们有人知道是什么地方出了问题以及如何解决吗?

python tkinter tooltip
1个回答
1
投票

Tkinter不允许你用按钮定义连锁包,因为 pack 不返回按钮对象。

只要把它分成两行,你的代码就能成功执行。

试试吧。

# Create some random widget
button = Button(root, text=" This is a Test", pady=30)
button.pack(pady=10)

结果:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.