How to change Tkinter Button Font?

Python Tkinter Button – Change Font

You can change the font properties like font-family, font size, font weight, etc., of Tkinter Button, by using tkinter.font package. In your Python program, import tkinter.font as font, create font.Font() object with required options and assign the Font object to font option of Button.

In this tutorial, we shall learn how to change the font-family, font size and font weight, with the help of well detailed example Python programs.

Pseudo Code – Change Button Font

Following is the pseudo code to change font style of Tkinter Button.

import tkinter.font as font

#create Font object
myFont = font.Font(family='Helvetica')

button = Button(parent, font=myFont)
#or
button = Button(parent)
button['font'] = myFont

Example 1: Change Font Family of tkinter Button

In this example, we will change the font family of tkinter button using family named argument provided to font.Font().

Python Program

from tkinter import *
import tkinter.font as font

gui = Tk(className='Python Examples - Button')
gui.geometry("500x200")

# define font
myFont = font.Font(family='Helvetica')

# create button
button = Button(gui, text='My Button', bg='#0052cc', fg='#ffffff')
# apply font to the button label
button['font'] = myFont
# add button to gui window
button.pack()

gui.mainloop() 

Output

tkinter button - change font family

Without font, the button would look like in the following GUI window.

Python tkinter button

You can compare the output of our next examples with this button and find how a font property has affected the button.

Example 2: Change Font Size of tkinter Button

You can also change font size of the text in tkinter Button, by passing named argument size to font.Font().

In this example, we will change the font size of tkinter button.

Python Program

from tkinter import *
import tkinter.font as font

gui = Tk(className='Python Examples - Button')
gui.geometry("500x200")

# define font
myFont = font.Font(size=30)

# create button
button = Button(gui, text='My Button', bg='#0052cc', fg='#ffffff')
# apply font to the button label
button['font'] = myFont
# add button to gui window
button.pack()

gui.mainloop() 

Output

tkinter button - change font size

Font size of the button is 30.

Example 3: Change Font Weight of tkinter Button

You can change font weight of the text in tkinter Button, by passing named argument weight to font.Font().

In this example, we will change the font weight of tkinter button.

Python Program

from tkinter import *
import tkinter.font as font

gui = Tk(className='Python Examples - Button')
gui.geometry("500x200")

# define font
myFont = font.Font(weight="bold")

# create button
button = Button(gui, text='My Button', bg='#0052cc', fg='#ffffff')
# apply font to the button label
button['font'] = myFont
# add button to gui window
button.pack()

gui.mainloop() 

Output

Example 4: Change Font Family, Size and Style of Button

We can apply all the font styling together with font.Font().

In this example, we will change font family, font size and font weight.

Python Program

from tkinter import *
import tkinter.font as font

gui = Tk(className='Python Examples - Button')
gui.geometry("500x200")

# define font
myFont = font.Font(family='Helvetica', size=20, weight='bold')

# create button
button = Button(gui, text='My Button', bg='#0052cc', fg='#ffffff')
# apply font to the button label
button['font'] = myFont
# add button to gui window
button.pack()

gui.mainloop() 

Output

When you run this application, you will get the window

Python tkinter button with custom font properties

Let us change the font family to Courier and run the application.

myFont = font.Font(family='Courier', size=20, weight='bold')
Python tkinter Button font family

Summary

In this tutorial of Python Examples, we changed the font family, font size and font weight of tkinter Button, with the help of well detailed examples.