如何解决如何使评论显示在树视图表中的行上方?
我正在尝试在此处Display message when hovering over something with mouse cursor in Python
中描述一种方法from tkinter import *
class ToolTip(object):
def __init__(self,widget):
self.widget = widget
self.tipwindow = None
self.id = None
self.x = self.y = 0
def showtip(self,text):
"display text in tooltip window"
self.text = text
if self.tipwindow or not self.text:
return
x,y,cx,cy = self.widget.bBox("insert")
x = x + self.widget.winfo_rootx() + 57
y = y + cy + self.widget.winfo_rooty() +27
self.tipwindow = tw = Toplevel(self.widget)
tw.wm_overrideredirect(1)
tw.wm_geometry("+%d+%d" % (x,y))
label = Label(tw,text=self.text,justify=LEFT,background="#ffffe0",relief=SOLID,borderwidth=1,font=("tahoma","8","normal"))
label.pack(ipadx=1)
def hidetip(self):
tw = self.tipwindow
self.tipwindow = None
if tw:
tw.destroy()
def CreatetoolTip(widget,text):
toolTip = ToolTip(widget)
def enter(event):
toolTip.showtip(text)
def leave(event):
toolTip.hidetip()
widget.bind('<Enter>',enter)
widget.bind('<Leave>',leave)
button = Button(root,text = 'click mem')
button.pack()
CreatetoolTip(button,text = 'Hello World')
但是该方法不适用于Treeview表。当我尝试执行以下代码时:
tree = ttk.Treeview(frame)
tree.pack()
CreatetoolTip(tree,text = 'Hello World')
出现错误:
Traceback (most recent call last):
File "/usr/lib/python3.8/tkinter/__init__.py",line 1883,in __call__
return self.func(*args)
File "/home/polina/PycharmProjects/dynamic_table/moxa.py",line 66,in enter
toolTip.showtip(text)
File "/home/polina/PycharmProjects/dynamic_table/moxa.py",line 46,in showtip
x,cy = self.widget.bBox("insert")
File "/usr/lib/python3.8/tkinter/ttk.py",line 1217,in bBox
return self._getints(self.tk.call(self._w,"bBox",item,column)) or ''
_tkinter.TclError: Item insert not found
当我们将鼠标悬停在行上时,是否还有另一种显示评论的方法?还是上述描述可以解决?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。