2
我想使用多個包含數據+ matplotlib滑塊小部件的matplotlib畫布。 問題是,滑塊控件沒有正確更新(貌似事件不會發送鼠標或東西)Python Matplotlib滑塊小部件未更新
這是我有:
import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from matplotlib.widgets import Slider
class PlotWidget(Tk.Frame):
def __init__(self, master):
Tk.Frame.__init__(self, master)
self.figure = Figure(figsize=(5,4), dpi=75)
self.canvas = FigureCanvasTkAgg(self.figure, self)
self.frame = self.canvas.get_tk_widget()
self.frame.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
self.canvas.show()
def add_slider(self):
a = self.figure.add_axes([0.25, 0.1, 0.65, 0.03], axisbg='lightgoldenrodyellow')
s = Slider(a, 'range', 0.1, 30.0, valinit=5)
self.canvas.show()
root = Tk.Tk()
option = 1
if option == 1 or option = 2:
w = PlotWidget(root)
w.pack()
figure = w.figure
else:
f = Tk.Frame(root, bd = 6, bg='red')
figure = matplotlib.figure.Figure(figsize=(5,4), dpi=75)
canvas = FigureCanvasTkAgg(figure, f)
canvas.get_tk_widget().pack()
canvas.show()
f.pack()
if option = 1:
w.add_slider()
else:
a = figure.add_axes([0.25, 0.1, 0.65, 0.03], axisbg='lightgoldenrodyellow')
s = Slider(a, 'range', 0.1, 30.0, valinit=5)
Tk.mainloop()
選項1不起作用其他所有組合做(在測試腳本中,至少在我的應用程序中,當我在另一個位置創建滑塊控件時,它也不起作用。 滑塊對鼠標事件沒有反應.....
我在想什麼?
我知道它必須是簡單的東西,但你現在正式成爲我的英雄! – Jori 2012-02-18 11:34:35