我正在尝试创建一个 Calltip(当您输入并保留一个开放括号时 IDLE 创建的内容):
class Calltip:
'''Creates a window similar to IDLE's call-tips'''
def __init__(self, widget, text, howLong = 100):
self.widget, self.text, self.howLong = widget, text, howLong
self.master = Toplevel(self.widget)
self.master.wm_overrideredirect(1)
self.label = Label(self.master, text = self.text)
self.label.pack()
self.label.update()
self.x, self.y, self.posX, self.posY = self.label.winfo_width(), self.label.winfo_height(), self.widget.winfo_rootx(), self.widget.winfo_rooty()
self.master.geometry("{xSize}x{ySize}+{x}+{y}".format(xSize = self.y, ySize = self.x, x = self.posX, y = self.posY))
self.widget.bind("<Enter>", (lambda event: self.show(event)))
def show(self, event):
'''Shows the calltip'''
print 'called'
self.__init__(self.widget, self.text, self.howLong)
self.master.geometry("+{x}+{y}".format(x = event.x_root, y = event.y_root))
time.sleep(self.howLong/100)
self.hide()
def hide(self):
'''Hides the calltip'''
self.master.destroy()
我希望它显示鼠标在哪里...但是,它总是出现在我屏幕的左角...任何原因,我该如何解决这个问题?