'How to embed a figure in tkinter window?

I have to embed the bode plot figure formed by using the control library the problem is that this command returns a matplotlib figure and I want to embed that figure as a whole into the tkinter window without using the plot command again because it is already plotted.

control.bode_plot(sys)

The figure returned by the bode_plot command

Please help.This is my first attempt at making a GUI using tkinter. Thanks.

The code:

root = Tk()
root.title("Self Biased PLL")
root.geometry("1280x720")
label1=Label(root,text="Input Clock Frequency ").grid(row=0,column=0)
field1 = Entry(root, width=18, borderwidth=2)
field1.grid(row=0, column=1,pady=10)
field1.insert(0,'0')
clock_in=float(field1.get())
label11=Label(root,text="Hz ").grid(row=0,column=3)

label2=Label(root,text="Output Frequency ").grid(row=1,column=0)
field2 = Entry(root, width=18, borderwidth=2)
field2.grid(row=1, column=1,pady=10)
field2.insert(0,'0')
freq_out=float(field2.get())
label12=Label(root,text="Hz ").grid(row=1,column=3)

label3=Label(root,text="Input Divider (N) ").grid(row=2,column=0)
field3 = Entry(root, width=18, borderwidth=2)
field3.grid(row=2, column=1,pady=10)
field3.insert(0,'0')
N=float(field3.get())

label4=Label(root,text="Gain of VCO (KVCO) ").grid(row=9,column=0)
slider1=Scale(root,from_=3,to=5,orient=HORIZONTAL)
slider1.grid(row=9,column=1,pady=10)
Kvco=float(slider1.get())
label13=Label(root,text="GHz/V ").grid(row=9,column=3)

label5=Label(root,text="Charge Pump Current (Ip) ").grid(row=11,column=0)
slider2=Scale(root,from_=500,to=1000,orient=HORIZONTAL)
slider2.grid(row=11,column=1,pady=10)
Ip=float(slider2.get())
label14=Label(root,text="uA ").grid(row=11,column=3)

label6=Label(root,text="C1 ").grid(row=5,column=0)
field6 = Entry(root, width=18, borderwidth=2)
field6.grid(row=5, column=1,pady=10)
field6.insert(0,'0.1')
C1=float(field6.get())
label15=Label(root,text="pF ").grid(row=5,column=3)

label7=Label(root,text="C2 ").grid(row=6,column=0)
field7 = Entry(root, width=18, borderwidth=2)
field7.grid(row=6, column=1,pady=10)
field7.insert(0,'0')
C2=float(field7.get())

label16=Label(root,text="pF ").grid(row=6,column=3)

label8=Label(root,text="R ").grid(row=7,column=0)
slider3=Scale(root,from_=500,to=1000,orient=HORIZONTAL)
slider3.grid(row=7,column=1,columnspan=1,pady=10)
R1 = slider3.get()

label17=Label(root,text="Ohm ").grid(row=7,column=3)

label18=Label(root,text=str(C2)).grid(row=8,column=3)

M=1

ff=control.tf([1],[M])

aa=control.tf([Ip],[2*np.pi])       #tf of PFD/CP
bb=control.tf([R1*C1,1],[C1,0])     #tf of LF
cc=control.tf([Kvco],[1,0])           #tf of VCO
dd=control.series(aa,bb,cc)            #Series combination

ee=control.feedback(dd,ff,-1)         #feedback

root.mainloop()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source