工作的一个项目,但不断收到错误
问题描述:
我试图运行一个Python项目,但我不断收到此错误工作的一个项目,但不断收到错误
异常在Tkinter的回调
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1538, in __call__
return self.func(*args)
File "C:\Users\davide\Desktop\Python Invetment Game\Main.py", line 115, in createb
create = tkinter.Button(createb, text="Create Business")
File "C:\Python34\lib\tkinter\__init__.py", line 2197, in __init__
Widget.__init__(self, master, 'button', cnf, kw)
File "C:\Python34\lib\tkinter\__init__.py", line 2120, in __init__
BaseWidget._setup(self, master, cnf)
File "C:\Python34\lib\tkinter\__init__.py", line 2098, in _setup
self.tk = master.tk
AttributeError: 'function' object has no attribute 'tk'
任何人都可以帮我http://pastebin.com/qDv7R1tA
答
这是你的功能createb
:
def createb():
creator = tkinter.Tk()
creator.geometry("800x768")
creator.title("Pyhton Business Creator")
global Type
Type = 0
def HD1():
global Type
Type = 1
global owner
owner = 1
if cash > 12500:
HD2 = tkinter.Button(createb, text="Hairdresser Business")
HD2.pack
create = tkinter.Button(createb, text="Create Business")
creator.mainloop()
您正试图在函数上创建按钮,这当然是不可能的。 因此,而不是:
HD2 = tkinter.Button(createb, text="Hairdresser Business")
create = tkinter.Button(createb, text="Create Business")
类型:
HD2 = tkinter.Button(creator, text="Hairdresser Business")
create = tkinter.Button(creator, text="Create Business")
BTW,它应该是HD2.pack()
而不是HD2.pack
。
请不要链接到其他网站上的代码。将其降低到可能的最小量。请参阅http://www.*.com/help/mcve。 –