繁体   English   中英

Python Tkinter-如何弹出按钮说明

[英]Python Tkinter - How to make a description pop up for a button

我根本不知道从哪里开始,所以我没有任何代码。 当您将鼠标悬停在按钮或任何小部件上时,有人知道弹出描述的方法吗?

def button_description(button, text, self):
    event = None
    self.del_search_description = lambda event=event: del_search_description(self)
    self.search_description = lambda event=event: search_description_delay(self, text, button)
    button.bind("<Enter>", self.search_description)
    button.bind("<Leave>", self.del_search_description)
def del_search_description(self, event=None):
    try:
        self.search_description_top.destroy()
    except AttributeError:
        pass
    return event
def search_description_delay(self, text, button, event=None):
    button.after(500 , search_description(self, text, button ,event))
def search_description(self, text, button, event=None):
    self.search_description_top = Toplevel()
    self.search_description_top.wm_overrideredirect(True)
    self.search_description_top_label = Label(self.search_description_top,
                                          text=text,
                                          justify=LEFT, background="gold",
                                          relief=SOLID, borderwidth=1, font='50')
    self.search_description_top_label.grid(row=0, column=0)
    x = button.winfo_rootx() - int(len(
    self.search_description_top_label.cget("text")) * 3.5) + int(button.winfo_width()/2)
    y = button.winfo_rooty() + 25
    self.search_description_top.geometry("+%s+%s" % (x, y))
    return event

调用button_description函数,并提供按钮或其他小部件,要放在描述中的文本以及运行tkinter代码的类(如果您位于代码所在的类之内,请输入self)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM