songsinuo 发表于 2021-3-28 20:39:32

tkinter模块报错

import tkinter
top=tkinter.Tk
label1=tkinter.Label(top,text='在窗体显示输出内容!')
label1.pack()
top.mainloop()



/Users/snow/PycharmProjects/pythoncrashcourse/venv/bin/python /Users/snow/PycharmProjects/pythonfromzerotoone/partone.py
Traceback (most recent call last):
File "/Users/snow/PycharmProjects/pythonfromzerotoone/partone.py", line 17, in <module>
    label1=tkinter.Label(top,text='在窗体显示输出内容!')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 2766, in __init__
    Widget.__init__(self, master, 'label', cnf, kw)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 2292, in __init__
    BaseWidget._setup(self, master, cnf)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 2262, in _setup
    self.tk = master.tk
AttributeError: type object 'Tk' has no attribute 'tk'

Process finished with exit code 1



怎么才能不报错呢?

小伤口 发表于 2021-3-28 20:50:30

import tkinter
top=tkinter.Tk()
label1=tkinter.Label(top,text='在窗体显示输出内容!')
label1.pack()
top.mainloop()
这个要加括号才行哦~{:10_254:}
top=tkinter.Tk()

songsinuo 发表于 2021-3-28 21:30:06

小伤口 发表于 2021-3-28 20:50
这个要加括号才行哦~

谢谢
页: [1]
查看完整版本: tkinter模块报错