0

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.

Community
  • 1
  • 1
Kyle
  • 303
  • 8
  • 21

2 Answers2

2
tkinter.Button(self, text='Reset',relief='flat',font=('Verdana', 9,'bold','underline'))
sanjeev
  • 31
  • 2
  • 2
    Please review [How to write a good answer](https://stackoverflow.com/help/how-to-answer). Code-only answers are discouraged because they do not explain how they resolve the issue. You should update your answer to explain what this does and how it solves the problem. – FluffyKitten Oct 14 '17 at 01:33
1

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!

Constantly Confused
  • 595
  • 4
  • 10
  • 24
  • Still not displaying an underline, if I change the code you have and put `font="Verdana 10 bold"` it goes bold though. – Kyle Dec 09 '15 at 01:57
  • Hmm, I guess it's because you're on a Mac, try looking at some tkFonts documentation, sorry I wasn't much help! I can't really probe your issue. – Constantly Confused Dec 09 '15 at 20:18