Tkinter标签窗口小部件中的下划线文本?
我正在做一个项目,要求我在Tkinter标签窗口小部件中的某些文本下划线。我知道可以使用下划线方法,但是基于参数,我似乎只能使它在小部件的1个字符下划线。即
p = Label(root, text=" Test Label", bg='blue', fg='white', underline=0)change underline to 0, and it underlines the first character, 1 the second etc
我需要能够在小部件中的所有文本下划线,我敢肯定这是可能的,但是如何?
我在Windows 7上使用Python 2.6。
回答:
要对标签小部件中的所有文本加下划线,您需要创建一个将underline属性设置为True的新字体。这是一个例子:
import Tkinter as tkimport tkFont
class App:
    def __init__(self):
        self.root = tk.Tk()
        self.count = 0
        l = tk.Label(text="Hello, world")
        l.pack()
        # clone the font, set the underline attribute,
        # and assign it to our widget
        f = tkFont.Font(l, l.cget("font"))
        f.configure(underline = True)
        l.configure(font=f)
        self.root.mainloop()
if __name__ == "__main__":
    app=App()
以上是 Tkinter标签窗口小部件中的下划线文本? 的全部内容, 来源链接: utcz.com/qa/412366.html







