Welcome folks today in this blog post we will be changing tkinter label fonts
and underline them also in python. All the full source code of application is given below.
Get Started
In order to get started you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
from tkinter import * from tkinter.font import Font root = Tk() text = Text(root) text.pack(fill=BOTH, expand=YES) text.tag_configure("bold", font=Font(weight="bold")) text.tag_configure("italic", font=Font(slant="italic")) text.tag_configure("underline", font=Font(underline=True)) text.tag_configure("bold-italic", font=Font(weight="bold", slant="italic")) text.insert(END, "Python is a programming language.") text.tag_add("bold", "1.0", "1.4") text.tag_add("bold-italic", "1.2", "1.3") text.tag_add("italic", "1.4", "1.10") text.tag_add("underline", "1.10", END) root.mainloop() |
Now if you execute the above python script by typing the below command as shown below
python app.py