How To Use Or Customize Fonts In Python Tkinter Labels

In the last articles, I have explained about various topics like Tkinter Introduction, Labels and using images in the Labels.If you are unaware about these.You can check previous articles here.

Also Read : Python Tkinter Label Tutorial and Example

Also Read : How To Use Images In Python Tkinter Labels

In this Tutorial I would like to explain about the fonts like font Sizes, Types and Background Colors etc using Tkinter Labels.So that using this Tk widget you can write your own text and backgrounds with your favorite colors.

Let me write Some Code To Explain these things very easily.

from Tkinter import *

main = Tk()

Label(main, 
		 text="Red Text in Times Font",
		 fg = "red",
		 font = "Times").pack()
Label(main, 
		 text="Green Text in Helvetica Font",
		 fg = "light green",
		 bg = "dark green",
		 font = "Helvetica 16 bold italic").pack()
Label(main, 
		 text="Blue Text in Verdana bold",
		 fg = "blue",
		 bg = "yellow",
		 font = "Verdana 10 bold").pack()

main.mainloop()

Please refer to previous articles about main and mainloop() variables

Also Read :   How To Use Images In Labels | Python Tkinter Tutorials

Also Read : Python Tkinter Label Tutorial and Example

Here we are creating three different labels which have different parameters.In all the previous articles we have created so many labels with main as our parent window.

All the Labels in this script should point to parent window (main variable only).Then We have some other parameters like text, fg, bg and font.

Text parameter is used to display the desired text. fg parameter is used to define font color of the given text and bg is used for the background color of the text.Finally, font is used to define the font type of the text.In our case, we are using three different font types (Times,Helvetica and Verdana).

Also Read :   Python GUI Tkinter Tutorials Introduction | Examples

Now Just run the script and analyze the code with your own parameter values. 🙂 Output Will be as follows :

python-tkinter-label-font

Let me know If you have any doubts.

Please, Like Our Facebook Page For More Updates and Comment Here.

Leave a Reply

Your email address will not be published. Required fields are marked *