2016-05-17 68 views
-3

我試圖運行一個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

+1

請不要鏈接到其他網站上的代碼。將其降低到可能的最小量。請參閱http://www.stackoverflow.com/help/mcve。 –

回答

0

這是你的功能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

相關問題