我要导入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(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()
我收到以下错误:Traceback (most recent call last):
File "exercise.py", line 2, in <module>
import tkFont
ModuleNotFoundError: No module named 'tkFont'
最佳答案
您可能正在尝试在 Python 3 下运行 Python 2 代码,这对库进行了一些重组。
如果您将当前导入替换为 import tkinter.font as TkFont
这应该足以插入你前进。
关于python - 无法导入 tkFont,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56735255/