Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x latex的python表达式_Python 3.x_Tkinter_Latex - Fatal编程技术网

Python 3.x latex的python表达式

Python 3.x latex的python表达式,python-3.x,tkinter,latex,Python 3.x,Tkinter,Latex,我正在尝试使用GUI显示方程式。我用乳胶和帆布。但是,我收到一条错误消息ValueError:KeyPress event keysym=Return keycode=36 char='\r'x=266 y=8 它应该可以工作,因为我已经将python表达式转换为Latex表达式 from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg import matplotlib import matplotlib.pyplot as

我正在尝试使用GUI显示方程式。我用乳胶和帆布。但是,我收到一条错误消息ValueError:KeyPress event keysym=Return keycode=36 char='\r'x=266 y=8

它应该可以工作,因为我已经将python表达式转换为Latex表达式

from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import matplotlib
import matplotlib.pyplot as plt
from tkinter import *
from sympy import *
matplotlib.use('TkAgg')

root=Tk()
frame=Frame(root)
frame.pack()

frame1= Frame()
frame1.pack()
caracter=StringVar()

def  result(caracter):
    a = str(caracter)
    text1=latex(a)
    ax.clear()
    ax.text(0.2, 0.6, "$"+text1+"$", fontsize = 6)  
    canvas.draw()



def element(num):
    caracter.set(caracter.get()+num)

#-----------------------------SCREEN------------
screen=Entry(frame, width=50, textvariable=caracter)
screen.pack()
screen.grid(row=1, column=1, pady=10, columnspan=5)
#-----------------------BUTTONS-----------------------
go=Button(frame, height=1, text="Go")
go.grid(row=1, column=6)

Buttonx=Button(frame, text="x", width=5, padx=0, pady=2, command=lambda:element("x"))
Buttonx.grid(row=2, column=6)

#--------CANVAS ---------------    
label = Label(frame1)
label.pack()



fig = matplotlib.figure.Figure(figsize=(5, 4), dpi=100)
ax = fig.add_subplot(111)

canvas = FigureCanvasTkAgg(fig, master=label)
canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
canvas._tkcanvas.pack(side=TOP, fill=BOTH, expand=1)

ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)

root.bind('<Return>', result)



root.mainloop()
来自matplotlib.backends.backend\u tkagg导入图CAVASTKAGG
导入matplotlib
将matplotlib.pyplot作为plt导入
从tkinter进口*
从sympy进口*
matplotlib.use('TkAgg')
root=Tk()
帧=帧(根)
frame.pack()
frame1=Frame()
frame1.pack()
caracter=StringVar()
def结果(字符):
a=str(字符)
text1=乳胶(a)
ax.clear()
ax.text(0.2,0.6,“$”+text1+“$”,fontsize=6)
canvas.draw()
def元素(数量):
caracter.set(caracter.get()+num)
#-----------------------------屏风------------
屏幕=输入(帧,宽度=50,文本变量=字符)
screen.pack()
screen.grid(行=1,列=1,pady=10,列span=5)
#-----------------------钮扣-----------------------
go=按钮(框架,高度=1,text=“go”)
go.grid(行=1,列=6)
Buttonx=按钮(框架,text=“x”,宽度=5,padx=0,pady=2,命令=lambda:element(“x”))
Buttonx.grid(行=2,列=6)
#--------帆布------------------
标签=标签(框架1)
label.pack()
fig=matplotlib.figure.figure(figsize=(5,4),dpi=100)
ax=图添加_子批次(111)
画布=图CAVASTKAGG(图,主视图=标签)
canvas.get_tk_widget().pack(side=TOP,fill=BOTH,expand=1)
帆布包装(侧边=顶部,填充=两侧,展开=1)
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
root.bind(“”,结果)
root.mainloop()

这是重现问题的最短代码。任何帮助或暗示都将不胜感激。提前非常感谢

您正在将与
相关的字符传递给您的函数
结果
。由于参数名为
caracter
,因此这会隐藏先前声明为
tk.StringVar
的变量
caracter

类似这样的内容应该会给您带来预期的结果:

def result(dummy_c):
    a = caracter.get()
    text1 = latex(a)
    ax.clear()
    ax.text(0.2, 0.6, "$"+text1+"$", fontsize = 6)  
    canvas.draw()

谢谢你的回答,这对我帮助很大,是的,我现在可以看到这个等式了。我一直在寻找那些指南。从现在起,我将跟随他们。非常感谢。