Quantcast

Embedding, Drawing, Curser in Tkinter

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Embedding, Drawing, Curser in Tkinter

stefanxfg
This post has NOT been accepted by the mailing list yet.
Hello to everyone.

I develop a GUI and i want to embedd Matplotlib in a Tkinter Canvas. Theres is no problem until here. But i want to draw the lines and have a curser line in the diagram. In the code below i embedd the canvas in the INIT-Function.

 <nabble_embed> class BOStrab_Fahrzeugeinschraenkung: def __init__(self, top=None): ...... self.ya = np.array(ddd) self.yb = np.array(ddd) self.z = np.array(ddd) self.canvasframe11 = Frame(self.TPanedwindow4_f2) self.canvasframe11.place(x=0, y=0, relwidth=1.0, relheight=0.95, bordermode=INSIDE) self.canvasframe12 = Frame(self.TPanedwindow4_f2) self.canvasframe12.place(x=0, rely=0.95, relwidth=1.0, bordermode=INSIDE) global ax1 self.fig1 = Figure (figsize=(5,4), dpi=100) self.ax1 = self.fig1.add_subplot(111) #für 2d-Plot self.ax1.set_title('Definition der LRUGL') self.ax1.set_xlabel('Breite y [mm]') self.ax1.set_ylabel('Hoehe z [mm]') self.ax1.axis([-2000,2000,0, 5000]) self.ax1.grid(True) self.ax1.plot(self.ya,self.z, color='red', linestyle='--', marker='') self.ax1.plot(self.yb,self.z, color='red', linestyle='--', marker='') self.canvas1 = FigureCanvasTkAgg(self.fig1,self.canvasframe11) toolbar1 = NavigationToolbar2TkAgg(self.canvas1, self.canvasframe12) self.canvas1.get_tk_widget().pack(fill=BOTH, expand=TRUE, pady=2, padx=2, anchor="n") </nabble_embed>

In several examples i saw the drawing in def's and the input for the drawing from root. So the following code is function then.

<nabble_embed> def onMouseMove(event): ax1.lines = [ax1.lines[0]] ax1.axhline(y=event.ydata, color="k") ax1.axvline(x=event.xdata, color="k") def updateData(): global level1, val1 clamp = lambda n, minn, maxn: max(min(maxn, n), minn) yield 1 # FuncAnimation expects an iterator def visualize(i): lineVal1.set_ydata(val1) return lineVal1 </nabble_embed>

My question is. Is my way to embedd the code in Tkinter right? Or its better to declare the diagram functionalities outside the class and only draw into the class?

Best regards from Stefan
Loading...