0
我想創建一個Calltip的(什麼IDLE,當你進入,並保持開放的括號創建):位置設在Tkinter的一個窗口關閉鼠標事件
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()
我想讓它顯示無論鼠標...但是,它總是出現在我的屏幕的左下角......任何原因,以及如何解決這個問題?