How to change Tkinter Button font style?

Python Tkinter Button – Change Font Style

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

Examples

1. Change font family of Button to Helvetica

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()
Copy

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.

2. Change font size of tkinter Button to 30

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()
Copy

Output

tkinter button - change font size

Font size of the button is 30.

3. Change font weight of tkinter Button to bold

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()
Copy

Output

How to change Tkinter Button font style?

4. Change font family, size, and style of Button in a single statement.

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()
Copy

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.

Related Tutorials

Code copied to clipboard successfully 👍