Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法导入tkFont_Python_Tkinter - Fatal编程技术网

Python 无法导入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

我想导入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()
我发现以下错误:

回溯(最近一次呼叫最后一次):

文件“exercise.py”,第2行,在

导入tkFont


ModuleNotFoundError:没有名为“tkFont”的模块。

您可能正在尝试在Python 3下运行Python 2代码,Python 3对库进行了一些重组

如果您将当前导入替换为
import tkinter.font as TkFont
,这应该足以推动您前进。

可能的重复