0

I tried everything online and it doesnt work. I just want a 2d graph that represents the result which is a matrix. Let´s say this part of my code it´s a calculator for matrices, and I´m having trouble at the moment to make a pop up screen that shows a graph after giving the result. Btw I´m not missing any library.

 def inversa():
        a11=float(k1.get()) #saves user imput
        a12=float(k2.get())
        b21=float(k4.get())
        b22=float(k5.get())
        R1=[]
        R2=[]
        R1.append(a11)
        R1.append(a12)
        R2.append(b21)
        R2.append(b22)
        A =[R1,R2]
        A = np.matrix(A)
        mat2=np.linalg.inv(A)
        tkinter.messagebox.showinfo("The inverse matrix is : ","%s"%mat2)
alekens
  • 11

1 Answers1

0

I would suggest looking into Placing Plot on Tkinter Main Window in Python. You can use matplotlib to first plot the graph and then place it into a tkinter window.

To integrate a matplotlib graph into tkinter a backend class of matplotlib namely FigureCanvasTkAgg can be used.

To import it -:

from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

And then a figure object can be used to place a plotted graph figure on the figure canvas like so -:

fig = Figure(...) # Initializing the figure object.
canvas = FigureCanvasTkAgg(fig, master=root) # Initializing the FigureCanvasTkAgg Class Object.
tk_canvas = canvas.get_tk_widget() # Getting the Figure canvas as a tkinter widget.
tk_canvas.pack() # Packing it into it's master window.
canvas.draw() # Drawing the canvas onto the screen.

Also the plotting of the figure object can be done using matplotlib methods.

So the complete code becomes -:

from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

fig = Figure(...) # Initializing the figure object.
canvas = FigureCanvasTkAgg(fig, master=root) # Initializing the FigureCanvasTkAgg Class Object.
tk_canvas = canvas.get_tk_widget() # Getting the Figure canvas as a tkinter widget.
tk_canvas.pack() # Packing it into it's master window.
canvas.draw() # Drawing the canvas onto the screen.
typedecker
  • 1,351
  • 2
  • 13
  • 25