How to change the size of text on a label in Tkinter?

TkinterPythonGUI-Programming

The label widget in Tkinter is used to display text and images in a Tkinter application. In order to change the properties of the label widget such as its font-property, color, background color, foreground color, etc., you can use the configure() method.

If you want to change the size of the text in a Label widget, then you can configure the font=('font-family font-size style') property in the widget constructor.

Example

# Import the required libraries
from tkinter import *
import tkinter.font as tkFont

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

# Set the size of the tkinter window
win.geometry("700x350")

def font_style():
   label.config(font=('Helvetica bold', 26))

# Create a Label
label = Label(win, text="Click the Button to Change the Font Style.", font=('Times', 24))
label.pack()

b1 = Button(win, text="Change the Label Size", command=font_style)
b1.pack()

win.mainloop()

Output

When you run the above code, it will display a window with a label widget and a button to change the font style of the label.

Now, click the "Change the Label Size" button and it will modify the font style of the label.

raja
Published on 06-Aug-2021 07:47:46
Advertisements