2015-12-08 68 views
0

按钮文本下划线选项不起作用。这是我已经试过:Tkinter - 下划线按钮文本

boldFontOpts = tkFont.Font(weight='bold') 
    self.boldButton = Button(self.toolbarFrame, text='B', command=self.boldfunc, 
     width=bWidth, height=bHeight) 
    self.boldButton['font'] = boldFontOpts 
    self.boldButton.grid(sticky=W, padx='4', row=1, column = 0) 

    self.underlineButton = Button(self.toolbarFrame, text='U', command=self.underlinefunc, 
     width=bWidth, height=bHeight) 
    underlineFontOpts = tkFont.Font(self.underlineButton, self.underlineButton.cget('font')) 
    underlineFontOpts.configure(underline=True) 
    self.underlineButton.configure(font=underlineFontOpts) 
    self.underlineButton.grid(sticky=W, padx='3', row=1, column = 1) 

用于下划线按钮(不工作)的代码是摘自: Underline Text in Tkinter Label widget?

我也用了代号为大胆的按钮( ),但当weight='bold'被替换为underline=1underline=True并且所有相应的变量名称等被改变(显然)时,它不起作用。

那么,这个按钮文字怎么可以加下划线?

附加信息: - 在Mac - Python的3 - 调色剂,8.5

编辑: 我将这两行:

font = tkFont.Font(font=self.underlineButton['font']) 
print(font.actual()) 

并在终端上面说'underline': 1,但仍然不不显示下划线。

+0

你是否在MAC? –

+0

是的,我会加到问题 – Kyle

回答

1

当您创建按钮,尝试做这样的事情:

button = Button(window, text="Sample", font= "Verdana 10 underline") 

这然后设置按钮的字体带下划线的风格。

希望我帮了忙!

+0

如果我改变你的代码,并且把'font =“Verdana 10 bold”'仍然没有显示下划线, – Kyle

+0

嗯,我想这是因为你在Mac上,试着看看一些tkFonts文档,对不起,我没有太多帮助!我无法真正解决你的问题。 –

-1
tkinter.Button(self, text='Reset',relief='flat',font=('Verdana', 9,'bold','underline')) 
+0

对此更清楚一点? –

+0

请回顾[如何写出一个好答案](https://stackoverflow.com/help/how-to-answer)。不接受代码的答案是不鼓励的,因为他们没有解释他们如何解决问题。你应该更新你的答案,以解释这是什么以及如何解决问题。 – FluffyKitten