from tkinter import *
# You need to import matplotlib Figure Canvas (TkAgg)
import matplotlib
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
matplotlib.use('TkAgg')
# the container must be a tkinter Label and the text must be a latex code
def graph(container, text, width, height, position=(-0.15, 0.35), font_size=41):
figure = matplotlib.figure.Figure(figsize=(width, height), dpi=100)
equation = figure.add_subplot(111)
canvas = FigureCanvasTkAgg(figure, master=container)
canvas.get_tk_widget().pack(side="top", fill="both", expand=True)
canvas._tkcanvas.pack(fill="both", expand=True, side="top")
equation.get_xaxis().set_visible(False)
equation.get_yaxis().set_visible(False)
equation.spines["right"].set_visible(False)
equation.spines["left"].set_visible(False)
equation.spines["top"].set_visible(False)
equation.spines["bottom"].set_visible(False)
equation.clear()
equation.text(position[0], position[1], "$"+text+"$", fontsize=font_size)
canvas.draw()
root = Tk()
root.geometry("625x225")
root.title("Latex Viewer")
label = Label(root)
label.pack(pady=10, padx=10)
graph(label, r"|-2(sqrt[12]{frac{8192}{2}})| = -8x", 15, 2)
# When you type latex code in string you need to add 'r' (r"<LaTeX>") because in python string "" is used in editing ("
", """, "'", "")
# if latex code is stored in a variable you can use this: eval("r'"+variable+"'")
root.mainloop()
# By the way can you solve the equation?