1

How should one go about maintaining leap motion's listener frame callback with python tkinter's mainloop?

The controller's constant callback happens at the same time as Tkinter's mainloop.

also:

1) Is this called multi-threading?

2) What gui do you use when developing in python with leap motion?

Thanks!

user3431429
  • 101
  • 1
  • 7
  • Could you provide sample code for the leap motion callback and when and how often it happens? Also sample code of how Tkinter works would be nice. Your question connects leap motion and tkinter. It is very rare that you will find people knowing both at the same time. – User Apr 16 '14 at 11:36

1 Answers1

1

There is a Tkinter + Leap Motion example here: Leap_Touch_Emulation

I wrote it, and it is the only Tkinter program I have written, but it does illustrate the basics of creating and using a listener.

1) Yes, Leap Motion listeners are multithreaded -- each callback function is executed on a separate thread.

You could also just get the Leap Motion tracking data at a convenient point in the Tkinter loop -- and not use a listener at all. It looks like the after() function would be a good place to do this:

from Tkinter import *
import Leap
root=Tk()
controller = Leap.Controller()

def task():
    frame = controller.frame()
    root.after(1/60,task)  # 60 fps

root.after(1/60,task)
root.mainloop() 

(adapted from: How do you run your own code alongside Tkinter's event loop)

This can improve the responsiveness of you application since you are only processing one frame of Leap Motion tracking data per main loop iteration instead of up to 4.

2) That's a different question, and probably not the type appropriate for stack overflow. For non-graphic-intensive samples I use Tkinter because it is built-in. For things with types of drawing that aren't easily achievable with Tkinter, I've been using pyglet/OpenGL.

Community
  • 1
  • 1
Charles Ward
  • 1,388
  • 1
  • 8
  • 13
  • `root.after(0, task)` is a bit dangerous, because you may not give Tkinter time to handle "non-after" tasks. It's better to give a small non-zero number rather than 0. – Bryan Oakley Apr 17 '14 at 17:26
  • Thanks, Bryan, I I misinterpreted ``after`` as ms after the main loop function executes -- updated. – Charles Ward Apr 17 '14 at 17:43