按钮实例没有 __call__ 方法
Button instance has no __call__ method
我想在 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()
而错误是:
self.makeWidgets(stock_sym)
AttributeError: Button instance has no __call__ method
我这样做是完全错误的还是有简单的方法来解决这个问题?任何帮助将不胜感激。
你的变量
self.makeWidgets = tk.Button(self)
与您的 class 方法同名
def makeWidgets(self, stock_sym):
先尝试改变这个
我想在 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()
而错误是:
self.makeWidgets(stock_sym)
AttributeError: Button instance has no __call__ method
我这样做是完全错误的还是有简单的方法来解决这个问题?任何帮助将不胜感激。
你的变量
self.makeWidgets = tk.Button(self)
与您的 class 方法同名
def makeWidgets(self, stock_sym):
先尝试改变这个