Underline Text in Tkinter Label widget?

Viewed 40363

I am working on a project that requires me to underline some text in a Tkinter Label widget. I know that the underline method can be used, but I can only seem to get it to underline 1 character of the widget, based on the argument. i.e.

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

I need to be able to underline all the text in the widget, I'm sure this is possible, but how?

I am using Python 2.6 on Windows 7.

8 Answers

oneliner

mylabel = Label(frame, text = "my label", font="Verdana 15 underline")

Try this for underline:

mylbl=Label(Win,text='my Label',font=('Arial',9,'bold','underline'))
mylbl.grid(column=0,row=1)
mylabel = Label(frame, text = "my label")
mylabel.configure(font="Verdana 15 underline")
p = Label(root, text=" Test Label", bg='blue', fg='white', font = 'helvetica 8 underline')

put your own font (i choose helvetica 8)

To underline all the characters you should import tkinter.font and make your own font style with this. Example-

from tkinter import *
from tkinter.font import Font
rt=Tk()
myfont=Font(family="Times",size=20,weight="bold", underline=1)
Label(rt,text="it is my GUI".title(),font=myfont,fg="green").pack()
rt.mainloop()

should in this format:

dev_label=Label(Right_frame,text="purxxx@gmail.com", font=("Times",15,"bold italic underline"),fg="black",bg="white") dev_label.place(x=80,y=120)

Related