0
我根本不知道從哪裏開始,所以我沒有任何代碼。有沒有人知道當您將鼠標懸停在某個按鈕或任何窗口小部件上時,會出現一種描述方式?Python Tkinter - 如何使按鈕彈出一個按鈕
我根本不知道從哪裏開始,所以我沒有任何代碼。有沒有人知道當您將鼠標懸停在某個按鈕或任何窗口小部件上時,會出現一種描述方式?Python Tkinter - 如何使按鈕彈出一個按鈕
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的代碼運行類(字通自我,如果你是所在班級內你的代碼是)
*「我根本不知道從哪裏開始」* - 那麼你還沒有準備好在這裏提出問題。 – jonrsharpe