How to do animation with joystick

this is my code i am having problem with joystick animation.
i know how to animate it without a joystick but when i am adding a joystick its not animating :frowning:
anyone please help. ?

from math import pi, sin, cos
 
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from direct.actor.Actor import Actor
from pandac.PandaModules import loadPrcFileData
from direct.showbase.ShowBase import ShowBase
from direct.gui.OnscreenText import OnscreenText
import direct.directbase.DirectStart
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *
from pandac.PandaModules import TextNode
from direct.gui.DirectGui import DirectFrame
from direct.showbase.ShowBase import ShowBase
from pandac.PandaModules import loadPrcFileData
from direct.showbase.ShowBase import ShowBase
loadPrcFileData("", "fullscreen 1")
import pygame
from pygame import locals
 
from direct.showbase.DirectObject import DirectObject   # for event handling
import direct.directbase.DirectStart
import sys
 
class World(DirectObject):
   def __init__(self):
      self.accept("escape",sys.exit)
 
w= World()
 
 
 
 
class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        pygame.init()
 
        pygame.joystick.init()
        j=pygame.joystick.Joystick(0)
        j.init()
       # y =  j.get_axis(1)
 
        # Load the environment model.
        #self.environ = self.loader.loadModel("My_Model/staticscene-final2.egg")
        self.environ = self.loader.loadModel("models/3d/staticscene-final2")
        # Reparent the model to render.
        self.environ.reparentTo(self.render)
        # Apply scale and position transforms on the model.
        self.environ.setScale(0.0125,0.0125, 0.0125)
        self.environ.setPos(12,22 , 0)
        self.CraneActor =Actor("My_Model/only-crane1",{'crane_move':'My_Model/only-crane-anim1'})
        myNodePath = self.CraneActor.exposeJoint(None,"modelRoot","Bone05")
        self.CraneActor.reparentTo(self.environ)
        self.Container=self.loader.loadModel("My_Model/container no2")
 
        #self.CraneActor.setScale(0.017,0.017,0.017)
 
 
        self.Container.reparentTo(myNodePath)
        self.Container.setScale(.89,0.35,1.02)
        self.Container.setPos(25,-215,0)
        #a=0
        #while a<100:
 
        for e in pygame.event.get():
         if e.type == pygame.locals.JOYAXISMOTION:
            if(  j.get_axis(1) <0):
             self.CraneActor.play("crane_move",fromFrame=50)
            if (  j.get_axis(1) >0):
             self.CraneActor.play("crane_move",fromFrame=100)
        #  a=a+1
       # self.Container.setHpr(90,0,0)
       # self.Container.reparentTo(self.CraneActor)
       # myAnimControl=self.CraneActor.getAnimControl('crane_move')
        #Joystick Controlling goes over here
      #  try:
 
          #print 'Enabled joystick' + j.get_name()
 
        # except pygame.error:
         # w= World()
 
 
    #elif e.type == pygame.locals.JOYBALLMOTION: # 8
    #       print 'ball motion'
    #elif e.type == pygame.locals.JOYHATMOTION: # 9
    #       print 'hat motion'
    #elif e.type == pygame.locals.JOYBUTTONDOWN: # 10
    #        print 'button down'
    #elif e.type == pygame.locals.JOYBUTTONUP: # 11
    #        print 'button up'
 
       #Joystick COntrolling Ends Over here
 
       # self.CraneActor.loop("crane_move",fromFrame=0,toFrame=80)
        #self.CraneActor.play("crane_move",fromFrame=0,toFrame=80)
 
        #self.CraneActor.stop("crane_move")
 
 
 
 
app = MyApp()
app.run()