How to change a Tkinter widget's font style without knowing the widget's font family/size?

TkinterPythonServer Side ProgrammingProgramming

Tkinter’s widgets support properties and attributes such as font-family and font size which can be specified using the font(‘Font-Family’, font-size) property.

Example

In the following example, we have created a text label that can be configured by defining the font-family as “Times New Roman” and the font-size as “20”.

#Import the tkinter library
from tkinter import *

#Create an instance of tkinter frame
win = Tk()

#Set the geometry
win.geometry("650x250")

#Add a text label and add the font property to it
label= Label(win, text= "This is a New Text", font=('Times New Roman bold',20))
label.pack(padx=10, pady=10)

win.mainloop()

Output

Running the above code will display a window or frame with text,

raja
Published on 26-Mar-2021 11:16:32
Advertisements