我有一个tkinter标签
back_button = Label(self.about_frame, text = "Back", bg="black", fg="white", font=("Silkscreen", 18))
当用户用鼠标悬停在标签上时,我希望文本的字体从常规变为斜体。我应该怎么做呢?谢谢!
答案 0 :(得分:4)
import tkinter
from functools import partial
def font_config(widget, fontslant, event):
widget.configure(font=fontslant)
parent = tkinter.Tk()
text = tkinter.Label(parent, text="Hello Text")
text.bind("<Enter>", partial(font_config, text, "Helvetica 9 italic"))
text.bind("<Leave>", partial(font_config, text, "Helvetica 9"))
text.pack()
tkinter.mainloop()