2017-09-14 75 views
-4

我想在python中創建應用程序,所以我剛剛開始,我想單擊按鈕並顯示圖形!Button實例沒有__call__方法

但它不允許我這樣做。

代碼片段:

from Tkinter import * 
    import matplotlib 
    matplotlib.use('TkAgg') 
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg 
    from matplotlib.figure import Figure 
    import matplotlib.pyplot as plt 
def schart2(stock_sym): 
    df 
    df.astype(float) 
    labels =  ['day0','day1','day2','day3','day4','day5','day6','day7','day8','day9','day10','day11','day12','day13','day14','day15','day16','day17','day18','day19','day20','day21','day22','day23','day24','day25','day26','day27','day28','day29','day30'] 

    df.columns=labels 
    plt.subplots_adjust(left=0.1, bottom=0.15, right=0.99, top=0.95) 
    ax=plt.imshow(df, cmap=plt.cm.get_cmap("RdPu"), interpolation="nearest",aspect="auto") 
    plt.xticks(range(len(labels)), labels, rotation=90, va="top", ha="center") 

    plt.colorbar() 
    plt.title("Return rate Retention") 
    plt.xlabel("Retention Days") 
    plt.ylabel("Total Days") 
    fig=ax.get_figure() 
    plt.show() 

class StockChart(Frame): 
    def __init__(self, stock_sym=''): 
     Frame.__init__(self, parent=None) 
     self.pack(expand=YES, fill=BOTH) 
     self.create_widgets(stock_sym) 
     self.makeWidgets(stock_sym) 

    def create_widgets(self, stock_sym): 
     self.makeWidgets = tk.Button(self) 
     self.makeWidgets["text"] = "Hello World\n(click me)" 
     self.makeWidgets["command"] = self.makeWidgets 
     self.makeWidgets.pack(side="top") 

     self.quit = tk.Button(self, text="QUIT", fg="red", 
           command=root.destroy) 
     self.quit.pack(side="bottom") 

    def makeWidgets(self, stock_sym): 
     #self.f = graphData(stock_sym,12,26) 
     self.f = schart2(stock_sym) 
     self.canvas = FigureCanvasTkAgg(self.f) 
     self.canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) 
     self.canvas.show() 



if __name__ == '__main__': 
    StockChart('ACAD').mainloop() 

而且錯誤是:

self.makeWidgets(stock_sym) 
AttributeError: Button instance has no __call__ method 

我這樣做完全錯誤的或者是有一個簡單的方法來解決這一問題?任何幫助將不勝感激。

+2

似乎有像15級或20的錯誤和錯誤代碼你發佈了...你是寫這個還是它是來自各種來源的剪切和粘貼的組合?它有沒有跑,在早期階段? 你可以發佈一些更簡單的東西,在你修改一段代碼後產生了一個錯誤嗎? –

回答

1

你的變量

self.makeWidgets = tk.Button(self) 

具有相同的名稱類方法

def makeWidgets(self, stock_sym): 

首先嚐試改變這種

相關問題