Hi, I am new to working with the Leap Motion and i am trying to display the position of my hand depicted by a dot with Tkinter. The coordinates of my hand update quickly without Tkinter running, but when Tkinter is running, there is a lag in the time the red moves after my hand moves on the screen. Is there any way to fix this?
Here is my code:
'''from the leap motion website, with some modifications'''
from Tkinter import Frame, Canvas, YES, BOTH
import Leap
class TouchPointListener(Leap.Listener):
def on_init(self, controller):
print "Initialized"
def on_connect(self, controller):
print "Connected"
def on_frame(self, controller):
self.paintCanvas.delete("all")
frame = controller.frame()
app_width = 800
app_height = 600
pointable = frame.hands.frontmost
print(pointable)
if pointable.is_valid:
iBox = frame.interaction_box
leapPoint = pointable.palm_position
normalizedPoint = iBox.normalize_point(leapPoint, False)
app_x = normalizedPoint.x * app_width
app_y = (1 - normalizedPoint.y) * app_height
print(app_x,app_y)
interactionBox = frame.interaction_box
for pointable in frame.hands:
normalizedPosition = interactionBox.normalize_point(pointable.palm_position)
color = "red"
self.draw(normalizedPosition.x * 800, 600 - normalizedPosition.y * 600, 40, 40, color)
def draw(self, x, y, width, height, color):
self.paintCanvas.create_oval(x, y, x + width, y + height, fill=color, outline="")
def set_canvas(self, canvas):
self.paintCanvas = canvas
class PaintBox(Frame):
def init(self):
Frame.init(self)
self.leap = Leap.Controller()
self.painter = TouchPointListener()
self.leap.add_listener(self.painter)
self.pack(expand=YES, fill=BOTH)
self.master.title("Touch Points")
self.master.geometry("800x600")
# create Canvas component
self.paintCanvas = Canvas(self, width="800", height="600")
self.paintCanvas.pack()
self.painter.set_canvas(self.paintCanvas)
def main():
PaintBox().mainloop()
if name == "main":
main()