''' vp_tk_threading1.py using VPython (visual) and Tkinter together with the help of Python module thread (_thread) change the position of a 3D sphere in space with tk buttons get VPython Windows installer VPython-5.74.win32-py2.7.exe or VPython-5.74.win32-py3.2.exe from http://www.lfd.uci.edu/~gohlke/pythonlibs/ tested with Python27, Python32 and VPython574 by vegaseat 22feb2013 ''' import visual as vs try: # Python2 import Tkinter as tk import thread except ImportError: # Python3 import tkinter as tk import _thread as thread # will be global sphere = None def vthread(): global sphere vs.scene.title = "Sphere in space (3D drag with right mouse button)" vs.scene.autoscale = False sphere = vs.sphere(pos=(0, 0, 0), color=vs.color.green) def move_sphere_incr_x(event=None): """ moves along the original x axis incrementing x each time the Tkinter b_incr_x button is pressed """ x, y, z = sphere.pos sphere.pos = (x+1, y, z) def move_sphere_decr_x(event=None): """ moves along the original x axis decrementing x each time the Tkinter b_decr_x button is pressed """ x, y, z = sphere.pos sphere.pos = (x-1, y, z) root = tk.Tk() w = 280 h = 150 x = 450 y = 100 # use width x height + x_offset + y_offset (no spaces!) root.geometry("%dx%d+%d+%d" % (w, h, x, y)) root.title("Control Sphere from here") b_incr_x = tk.Button(root, text="move right on x axis (increment x)") # bind passes an event to function b_incr_x.bind("<Button-1>", move_sphere_incr_x) b_incr_x.grid(row=0, column=0, padx=20, pady=10) b_decr_x = tk.Button(root, text="move left on x axis (decrement x)") # bind passes an event to function b_decr_x.bind("<Button-1>", move_sphere_decr_x) b_decr_x.grid(row=1, column=0, padx=10) # use thread to do run VPython and Tkinter simultaneously # thread.start_new_thread(function, args) # args is an empty tuple here sphere = thread.start_new_thread(vthread, ()) root.mainloop()
Isn't it about time forums rewarded their contributors?
Contribute to this discussion and earn rewards points that can be cashed out for dollars.
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...
Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.
This is the result of previous question answered :
code for the listbox - datagridview interaction
At the top of the code ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...