Akash Kp
Akash Kp

Reputation: 11

I get an error while creating a instance of the Font class in Tkinter

The following line:

my_font = tk.font.Font(size=20)

Gives me the following error:

module tkinter has no attribute font

How to fix this.

Upvotes: 0

Views: 72

Answers (2)

toyota Supra
toyota Supra

Reputation: 4543

It should be like this.

import tkinter.font as tkFont
 
myFont = tkFont.Font(root, size=20)

Upvotes: 0

JRiggles
JRiggles

Reputation: 6780

font is imported separately from the main tkinter

This should work for you

import tkinter as tk
from tkinter.font import Font

Then you can do this

root = tk.Tk()
my_font = Font(root, size=20)

Upvotes: 1

Related Questions