Reputation: 63
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. What should I do?
Upvotes: 1
Views: 431
Reputation: 992
I don't think that there is a way for vpython and tkinter to work together. 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. 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. See glowscript.org/docs/VPythonDocs/controls.html
Upvotes: 1