Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.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 为什么函数不是';我一次也没打电话?(Python:Tkinter,Matplotlib)_Python 3.x_Matplotlib_Tkinter - Fatal编程技术网

Python 3.x 为什么函数不是';我一次也没打电话?(Python:Tkinter,Matplotlib)

Python 3.x 为什么函数不是';我一次也没打电话?(Python:Tkinter,Matplotlib),python-3.x,matplotlib,tkinter,Python 3.x,Matplotlib,Tkinter,我用Tkinter用Python编写了一段代码,但我遇到了一个问题 有一些代码: main.py: 将动画作为 def draw_动画(): copyfile(biological\u system\u filepath,'biological\u system\u parameters.tmp') a、 创建动画() 打印('完成了') 删除('biological\u system\u parameters.tmp')) 动画=按钮(根,text='animation',command=dr

我用Tkinter用Python编写了一段代码,但我遇到了一个问题

有一些代码:

main.py:

将动画作为
def draw_动画():
copyfile(biological\u system\u filepath,'biological\u system\u parameters.tmp')
a、 创建动画()
打印('完成了')
删除('biological\u system\u parameters.tmp'))
动画=按钮(根,text='animation',command=draw\u动画,宽度=50)
动画包()
root.mainloop()
animation.py:

def create_animation():
style.use('ggplot')
sns.set_调色板(sns.color_调色板(“hls”,2))
图=plt.图(图尺寸=(16,10))
轨迹=np.loadtxt('trackit.txt',分隔符='',解包=真)
energy=np.loadtxt('energy.txt',分隔符='',unpack=True)
velocity=np.loadtxt('velocity.txt',分隔符='',解包=True)
ax1=图添加_子图(2,2,(1,3),投影='3d')
obj1,=ax1.绘图(轨迹[0]、轨迹[1]、轨迹[2])
生物_系统=[]、[]、[]、[]、[]
生物_系统[0],生物_系统[1],生物_系统[2],生物_系统[3]=np.loadtxt(
'biological_system_parameters.tmp',分隔符='',unpack=True)
ax1.绘图(生物系统[0]/10,生物系统[1]/10,生物系统[2]/10,'o',标记大小=1)
轨迹\ xlim,轨迹\ ylim,轨迹\ zlim=adjust \ u limits3D('trackit.txt'))
ax1.set_xlim(轨迹_xlim)
ax1.set_ylim(轨迹_ylim)
ax1.设置轨道(轨道轨道)
ax1.set_xlabel('x[nm]”)
ax1.set_ylabel('y[nm]”)
ax1.set_zlabel('z[nm]”)
ax1.集合标题(“Trajektoria cząstki”)
ax2=图add_子批次(2,2,2)
obj2,=ax2.绘图(能量[0],能量[1])
energy\u xlim,energy\u ylim=调整限制('energy.txt')
ax2.设置\u xlim(能量\u xlim)
ax2.set_ylim(能量_ylim)
ax2.set_xlabel('t[ns]”)
ax2.set_ylabel('E[eV]”)
ax2.设置标题(“Wykres energii całkowitej od czasu”)
ax3=图add_子批次(2,2,4)
obj3,=ax3.plot(速度[0],速度[1])
velocity_xlim,velocity_ylim=调整限制('velocity.txt'))
ax3.set_xlim(速度_xlim)
ax3.set_ylim(速度_ylim)
ax3.set_xlabel('t[ns]”)
ax3.set_ylabel('v[m/s]”)
ax3.设置标题(“Wykres prędkości cząstki od czasu”)
def init():
obj1.设置_数据([],[])
obj1.set_3d_属性([])
obj2.设置_数据([],[])
obj3.设置_数据([],[])
返回obj1、obj2、obj3、,
定义动画(i):
非局部步长
j=i*步
如果j%1000==0:
印刷品(j)
obj1.设置_数据(轨迹[0,:j],轨迹[1,:j])
obj1.set_3d_属性(轨迹[2,:j])
obj2.设置_数据(能量[0,:j],能量[1,:j])
obj3.设置_数据(速度[0,:j],速度[1,:j])
返回obj1、obj2、obj3、,
阶跃=1000
帧数=数学地板(透镜(能量[0])/步)
ani=animation.FuncAnimation(图,animate,init_func=init,frames=frames_num,blit=True)
Writer=动画。writers['ffmpeg']
writer=writer(fps=60,metadata=dict(artist='Me'))
ani.save('animacja.mp4',writer=writer)
plt.show()
我不明白为什么反复调用函数
a.create_animation()
“完成了”。
直到我单击关闭动画窗口的红十字按钮后才会打印。我知道它被反复调用,因为我在
animate()
方法中打印“
j
”值

示例输出:

0 1000 2000 3000 4000 6000 8000 9000 10000 11000 12000 13000 14000 15000 16000 17000 18000 19000 20000 21000 22000 23000 24000 25000 26000 27000 28000 29000 30000 31000 32000 33000 34000 35000 0 1000 2000 3000 4000 5000完成


你需要分享你的
对象是什么。我不知道这个方法是从哪里来的,也不知道它为什么会挂起。显然,尽管您的代码停止执行。您假设该方法被反复调用,但它很可能在自己的循环中,直到关闭窗口才结束。您可能需要找到另一种方法来创建所需的动画。我很抱歉。我可以说得更具体一些。我编辑了一篇文章。您的示例中没有任何内容表明
a.create\u animation()
此处缺少可能是当前问题的代码。唯一一次调用
a.create_animation()
是单击按钮的结果,但是它可以在代码中的其他地方调用,因为很明显您没有包含某些内容。尝试编写一个。
plt.show()
生成一个循环。查看文档,您可以尝试
plt.show(block=False)
,除了使用matplotlib之外,您还必须找到一个解决方案。请让我知道它是否适合您,因为我不确定我是否正确理解文档。