Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to display equation in tkinter

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?
Comment

PREVIOUS NEXT
Code Example
Python :: turn off pycache python 
Python :: maximizar ventana tkinter python 
Python :: opening image in python 
Python :: draw line from 2 mouse event in image python 
Python :: pass argument to a py file 
Python :: skimage image read 
Python :: django prepopulated_fields 
Python :: flash messages django 
Python :: Change date format on django templates 
Python :: filter dataframe by index 
Python :: split list into list of lists python on every n element 
Python :: python matplotlib inline 
Python :: how to fill na python 
Python :: join two set in python 
Python :: no module named pyplot 
Python :: get parameters flask 
Python :: open a filename starting with in python 
Python :: shutil.make_archive 
Python :: pyplot set x range 
Python :: pandas read csv without index 
Python :: pandas to_csv delimiter 
Python :: make python look good 
Python :: den pfad der python datei rausfinden 
Python :: subplot adjust python 
Python :: python program for geometric progression 
Python :: sha256 pandas 
Python :: cv_bridge.core.CvBridgeError: [8UC4] is not a color format. but [bgr8] is. The conversion does not make sense 
Python :: extract images from bag file python 
Python :: pandas find median of non zero values in a column 
Python :: pypi toml 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =