Problem with vpython+tkinter

562 views
Skip to first unread message

Steven Masfaraud

unread,
Apr 23, 2014, 8:41:51 AM4/23/14
to vpytho...@googlegroups.com
Hi,

I am trying to control a Vpython Model by a little tkinter Interface.
In the code below, i am trying to move a box along the x axis by moving a slider in tkinter interface.
I get a strange errror "ValueError: invalid literal for float(): 0,000" from the tkinter slider that i don't get if comment/uncomment as showed in the code.
It seems like vpython can't work with tkinter.

As anyone ever worked with tkinter+vpython?

import visual as vs

import Tkinter as tk


class VisualModel:

def __init__(self):

self.scene=vs.display(center=(0,0,0),background=(1,1,1))

self.scene.exit=False

self.box=vs.box(pos=(0,0,0))

def Update(self,x):

self.box.pos=(x,0,0)


class ControlWindow(tk.Frame):

def __init__(self,vs_model):

self.window = tk.Tk()

self.vs_model=vs_model

tk.Frame.__init__(self, self.window)

self.slider = tk.Scale(self.window, from_=0, to=1,resolution=0.001,command=self.Update)

self.slider.pack(side=tk.LEFT)

self.window.mainloop()


def Update(self,arg=None):

x=self.slider.get()

print x

self.vs_model.Update(x)# Comment this line


vsm=VisualModel() # Comment this line

w=ControlWindow(vsm)# Comment this line

#w=ControlWindow(None)# Uncomment this line


--

Steven
Message has been deleted

Bruce Sherwood

unread,
Apr 23, 2014, 10:50:09 AM4/23/14
to vpytho...@googlegroups.com
I don't think it is possible to use Tkinter with VPython, which is based on the GUI library wxPython. Even with your program not giving an error, note that the box doesn't appear. This is due to the fact that the rendering of the 3D objects, and the handling of events, goes through the wxPython machinery, which is inaccessible when Tkinter takes over these responsibilities.

See the VPython example program widgets.py for how to access wxPython widgets. My impression is that the wxPython widget set is at least as powerful as that of Tkinter.

Steven Masfaraud

unread,
Apr 24, 2014, 5:29:05 AM4/24/14
to vpytho...@googlegroups.com


Le mercredi 23 avril 2014 16:50:09 UTC+2, Bruce Sherwood a écrit :
I don't think it is possible to use Tkinter with VPython, which is based on the GUI library wxPython. Even with your program not giving an error, note that the box doesn't appear. This is due to the fact that the rendering of the 3D objects, and the handling of events, goes through the wxPython machinery, which is inaccessible when Tkinter takes over these responsibilities.

See the VPython example program widgets.py for how to access wxPython widgets. My impression is that the wxPython widget set is at least as powerful as that of Tkinter.

I get this error while running this code on linux mint with the debian packages python-visual and python-tk providing Visual and Tkinter. On Windows with the distribution Winpython this code works perfectly!

Bruce Sherwood

unread,
Apr 24, 2014, 12:42:22 PM4/24/14
to vpytho...@googlegroups.com
What is "Winpython"? I tried your code with VPython 6 from vpython.org (using the python.org version of Python 2.7) and there was no display of the sphere. I should also point out that the debian package python-visual is very old.
Reply all
Reply to author
Forward
0 new messages