简体   繁体   English

如何在tkinter中显示vpython制作的animation?

[英]How to display animation made by vpython in tkinter?

from vpython import *
from tkinter import *

root=Tk()
frame=Frame(root)
frame.pack()
wall=box(pos=vector(0,1,0),size=vector(0.2,3,2),color=color.green)
floor=box(pos=vector(6,-0.6,0),size=vector(14,0.2,4),color=color.green)
Mass=box(pos=vector(12,0,0),velocity=vector(0,0,0),size=vector(1,1,1),mass=1.0,color=color.blue)
pivot=vector(0,0,0)
spring=helix(pos=pivot,axis=Mass.pos-pivot,radius=0.4,constant=1,thickness=0.1,coils=20,color=color.red)
eq=vector(9,0,0)
t=0
dt=0.01
while (t<50):
  rate(100)
  acc=(eq-Mass.pos)*(spring.constant/Mass.mass)
  Mass.velocity=Mass.velocity+acc*dt
  Mass.pos=Mass.pos+Mass.velocity*dt
  spring.axis=Mass.pos-spring.pos
  t=t+dt
root.mainloop()

When I run this code, a 'localhost page' will pop out to display the animation. However I wish to display the animation in the root (imported from tkinter ) of python instead of in other page.当我运行此代码时,将弹出一个“本地主机页面”以显示 animation。但是我希望在 python 的root (从tkinter导入)中显示 animation 而不是在其他页面中。 What should I do?我应该怎么办?

I don't think that there is a way for vpython and tkinter to work together.我不认为 vpython 和 tkinter 可以一起工作。 There are two issues: 1) The 3D display has to be rendered in a browser window, because it uses the WebGL-2 3D graphics library that is built into the browser.有两个问题: 1) 3D 显示必须在浏览器 window 中呈现,因为它使用浏览器内置的 WebGL-2 3D 图形库。 2) Even if that weren't the case, it's probably the case that there would be conflicts between event handling by vpython and event handling by tkinter. My guess is that the only way to use widgets in a VPython program is to use VPython widgets. 2) 即使不是这种情况,也可能是 vpython 的事件处理和 tkinter 的事件处理之间存在冲突。我的猜测是,在 VPython 程序中使用小部件的唯一方法是使用 VPython 小部件. See glowscript.org/docs/VPythonDocs/controls.html请参阅 glowscript.org/docs/VPythonDocs/controls.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM