I'm trying to write equations in Tkinter widgets. I managed to find help on this site, and implemented the solution with matplotlib. However, one problem I'm facing now is that the font size of the equation I write is not consistent throughout the equation. The fraction part is much smaller than the rest of the equation. I will be in need of writing many more complicated equations, and I would like for all the normal (not subscript and superscript) characters to be equal. How can I do this? Part of the code I'm using for this is:
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
def popup(msg):
popup = tk.Tk()
popup.geometry("400x200")
popup.wm_title("error")
popup.resizable(False,False)
label = tk.Label(popup,anchor=CENTER)
label.grid(row=0,column=0)
tk.Grid.rowconfigure(popup,0,weight=1)
tk.Grid.columnconfigure(popup,0,weight=1)
ok = tk.Button(popup, text="OK", command=popup.destroy)
ok.grid(row=1,column=0)
fig=matplotlib.figure.Figure(figsize=(4.17, 1), dpi=100)
ax = fig.add_subplot()
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
fig.patch.set_facecolor('#F0F0F0')
ax.axis("off")
canvas = FigureCanvasTkAgg(fig, master=label)
canvas.get_tk_widget().grid()
ax.text(0.5, 0.5, msg, fontsize=15, horizontalalignment='center', verticalalignment='center', transform=ax.transAxes)
canvas.draw()
popup.mainloop()
The msg
is written as r"$\frac{\sigma\ '_{v}}{p_{atm}}$ must be > 0.25"
.
CodePudding user response:
If you use a "display fraction" with \dfrac
in place of \frac
the fonts in the fraction will be the same size:
msg = r"$\dfrac{\sigma\ '_{v}}{p_{atm}}$ must be > 0.25"