python - Leap Motion + Pygame | Displaying text in window -


i'm trying use pygame library leap motion. i'm trying display of data leap motion in window, when try retrieve variable samplelistener class , feed main method, error:

attributeerror: 'function' object has no attribute 'avg_pos'

is there i'm misunderstanding class > method > variable structure?

here code i'm working with:

import leap, sys, pygame  #window  windowwidth = 800 windowheight = 600  #leap motion settings class samplelistener(leap.listener):      def on_init(self, controller):         print "initialized"      def on_connect(self, controller):         print "connected"      def on_disconnect(self, controller):         # note: not dispatched when running in debugger.         print "disconnected"      def on_exit(self, controller):         print "exited"      def on_frame(self, controller):         # recent frame , report basic information             if not self.frame.hands.empty:                 # first hand                 hand = self.frame.hands[0]                  # check if hand has fingers                 fingers = hand.fingers                 if not fingers.empty:                     # calculate hand's average finger tip position                     avg_pos = leap.vector()                     finger in fingers:                         avg_pos += finger.tip_position                     avg_pos /= len(fingers)                     print "hand has %d fingers, average finger tip position: %s" % (                           len(fingers), avg_pos)  #application loop def main():     pygame.init()     window = pygame.display.set_mode((windowwidth,windowheight))     pygame.display.set_caption("test123")      #surface      background = pygame.surface(window.get_size())     background = background.convert()     background.fill ((50,0,80))      if pygame.font:         font = pygame.font.font(none, 36)         text = font.render("%s" % samplelistener.on_frame.len(fingers), 1, (255, 255, 255))         textpos = text.get_rect(centerx=background.get_width()/2)         background.blit(text, textpos)      # create sample listener , controller     listener = samplelistener()     controller = leap.controller()      # have sample listener receive events controller     controller.add_listener(listener)      clock = pygame.time.clock()      while true:         clock.tick(60)         #handle input events         event in pygame.event.get():             if event.type == pygame.quit:                 sys.exit()                 # remove sample listener when done                 controller.remove_listener(listener)          window.blit(background, (0,0))         pygame.display.flip()  if __name__ == "__main__":     main() 

edit: here full traceback error -

line 53, in main     text = font.render("%s" % samplelistener.on_frame.avg_pos, 1, (255, 255, 255)) attributeerror: 'function' object has no attribute 'avg_pos' 

thanks!

to me seems might pygame.font not boolean, therefore can not used in if statement. ( quote:

def main(): pygame.init() window = pygame.display.set_mode((windowwidth,windowheight)) pygame.display.set_caption("test123")  #surface  background = pygame.surface(window.get_size()) background = background.convert() background.fill ((50,0,80))  if pygame.font: \\ here   <---     font = pygame.font.font(none, 36)     text = font.render("%s" % samplelistener.on_frame.len(fingers), 1, (255, 255, 255))     textpos = text.get_rect(centerx=background.get_width()/2)     background.blit(text, textpos) 

)


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -