如何在tkinter中的另一个类中更新matplotlib图形作为帧的子图形?这是我被困住的地方。
class A():
def__init__(self, master):
sframe = Frame(master)
sframe.pack(side=RIGHT)
f = Figure(figsize=(3,2), dpi=100)
a = f.add_subplot(122);
# initially plots a sine wave
t = arange(0.0, 1, 0.01);
s = sin(2*pi*t);
a.plot(t,s);
canvas = FigureCanvasTkAgg(f, master=sframe)
canvas.show()
canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
# now i create the other object that will call show()
data_obj = B(sframe)
class B():
...
show(self, frame):
_wlist = frame.winfo_children()
for item in _wlist:
item.clear() # or something like this
# and then re-plot something or update the current plot
答案 0 :(得分:0)
您必须以某种方式从show方法中检索您的图形对象f
。
B
构造函数
class B:
def __init__(self, frame, figure):
self.figure = figure
...
def show(self, frame):
...
self.figure.plot( something )
class A:
def__init__(self, master):
...
sframe.fig = f
data_obj = B(sframe)
class B:
def show(self, frame):
...
frame.fig.plot( something )