Button实例没有__call__方法

时间:2017-09-14 07:13:19

标签: python python-2.7 tkinter tkinter-entry

我想在python中创建应用程序,所以我刚开始,我想点击按钮,图形应该显示!!!

但它不允许我这样做。

代码段

    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()

ERROR 是:

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

我这样做是完全错误还是有一种简单的方法可以解决这个问题?任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

您的变量

self.makeWidgets = tk.Button(self)

与您的类方法具有相同的名称

def makeWidgets(self, stock_sym):

首先尝试更改此