Iyush Bajracharya
Iyush Bajracharya

Reputation: 139

Cannot import tkFont

I want to import tkFont but it's not working

from tkinter import *

import tkFont

class BuckysButtons:

def __init__(self,master):
    frame = Frame(master)
    frame.pack() 

   helv36 = tkFont.Font(family="Helvetica",size=36,weight="bold")


    self.printButton = Button(frame,font=helv36, text ="Print 
    Message",command = self.printMessage,compound ='top')
    self.printButton.pack(side =LEFT)
    
    self.quitButton = Button(frame, text ="quit", command = frame.quit)
    self.quitButton.pack(side=LEFT)


def printMessage(self):
    print("It worked!")

     root = Tk()
     b = BuckysButtons(root)
     root.mainloop()

i'm getting following error:

Traceback (most recent call last):
  File "exercise.py", line 2, in <module>
    import tkFont
ModuleNotFoundError: No module named 'tkFont'

Upvotes: 10

Views: 23998

Answers (1)

holdenweb
holdenweb

Reputation: 37003

It's possible you are trying to run Python 2 code under Python 3, which did some library reorganisation.

If you replace your current import with import tkinter.font as TkFont that should suffice to move you forward.

Upvotes: 27

Related Questions