python - 无法导入 tkFont

标签 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(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/

相关文章:

python - 如何在 show() 之后为 matplotlib 图设置 tight_layout

python - 如何从 Python 中的列表创建嵌套字典?

python - 这个数据结构有一个友好的名字吗?

带逗号的 Python Tkinter 格式数字条目

Python Tkinter : create a menu button on the right side

python - 将光标悬停在 Canvas 上时如何显示 Canvas 坐标?

python - 在 MxNet-Gluon 中将 ROIPooling 层与预训练的 ResNet34 模型结合使用

python - 制定一个算法,将电力单位分配给一周中的几天,并找出哪个是最少的

Python Tkinter : Canvas scrolling with MouseWheel

python - 如何在Python中使用filedialog将DataFrame保存到Excel文件?