我想在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 Worldn(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)
具有与您的类方法相同的名称
def makeWidgets(self, stock_sym):
首先尝试更改此