7

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'
nixalott
  • 15
  • 5
Iyush Bajracharya
  • 109
  • 1
  • 1
  • 6
  • Possible duplicate of [ImportError: No module named requests](https://stackoverflow.com/questions/17309288/importerror-no-module-named-requests) – Gpsy Jun 24 '19 at 11:12
  • Possible duplicate of [Python3 Tkinter fonts not working](https://stackoverflow.com/questions/32660387/python3-tkinter-fonts-not-working) – Arkadiusz Drabczyk Jun 24 '19 at 11:17

1 Answers1

24

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.

holdenweb
  • 33,305
  • 7
  • 57
  • 77