0
votes

Button text underline option, is not working. This is what I've tried:

    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)

The code used for the underline button (which doesn't work) was taken from: Underline Text in Tkinter Label widget?

I also used the code for the bold button (which works) for the underline button, however it doesn't work when the weight='bold' is substituted with underline=1 or underline=True and all appropriate variable names etc. are changed (obviously).

So, how can this button text be underlined?

Additional info: - On mac - Python 3 - tinter 8.5

Edit: I added these two lines:

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

And in the terminal it says 'underline': 1, yet still does not display the underline.

2
Yes, I'll add to question - Kyle

2 Answers

1
votes

When you create the button, try doing something like this:

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

This then sets the font of the button to an underlined style.

Hope I helped!

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