How to change the font and size of buttons and frame in tkinter?

TkinterServer Side ProgrammingProgramming

Tkinter Button Widgets are a general way to provide Event Handling in a variety of applications. Sometimes, we may need to style the buttons which are defined in an application. In order to add styling in the button widgets, first create an instance of Button widget using a variable. Then, add some property like fontfamily, font-size, padding, etc. into it. The most general way to resize the button is by resizing the text in it.

Example

In this example, we have created a button that can be resized by changing the value in the 'font' property.

#Import tkinter library
from tkinter import *
#Create an instance of tkinter frame
win= Tk()
#Set the Geometry
win.geometry("750x250")
def click_to_close():
win.destroy()
#Create a Button
button= Button(win, text= "Click to Close", font= ('Helvetica 20
bold italic'), command=click_to_close)
button.pack(pady=20)
win.mainloop()

Output

Running the given code will generate a button with some text in it which can be resized by changing the value of the font-size.

raja
Published on 15-Apr-2021 17:48:19
Advertisements