Python 无法导入tkFont
我想导入tkfont,但它不起作用Python 无法导入tkFont,python,tkinter,Python,Tkinter,我想导入tkfont,但它不起作用 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(fr
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()
我发现以下错误:
回溯(最近一次呼叫最后一次):
文件“exercise.py”,第2行,在
导入tkFont
ModuleNotFoundError:没有名为“tkFont”的模块。您可能正在尝试在Python 3下运行Python 2代码,Python 3对库进行了一些重组 如果您将当前导入替换为
import tkinter.font as TkFont
,这应该足以推动您前进。可能的重复