Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to change the font and size of buttons and frame in tkinter?
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.

Advertisements