2017-05-12 87 views
0

現在我試圖做到這一點,而不是點擊移動PlayerImage我想使用箭頭鍵,我嘗試實現左和右第一次,但然後當我測試了它,我得到這個:KIVY TypeError:on_keyboard_down()需要2個位置參數,但有5個被給出

完全回溯:

Traceback (most recent call last): 
    File "/Users/acrobat/Desktop/dive/test.py", line 91, in <module> 
    runTouchApp(root) 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/base.py", line 487, in runTouchApp 
    EventLoop.window.mainloop() 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/core/window/window_pygame.py", line 403, in mainloop 
    self._mainloop() 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/core/window/window_pygame.py", line 370, in _mainloop 
    self.modifiers): 
    File "kivy/_event.pyx", line 714, in kivy._event.EventDispatcher.dispatch (/private/var/folders/42/pdwcpzkj0j56rssch8hjpwnm0000gn/T/pip-build-oh1mgzrd/kivy/kivy/_event.c:8119) 
    File "kivy/_event.pyx", line 1224, in kivy._event.EventObservers.dispatch (/private/var/folders/42/pdwcpzkj0j56rssch8hjpwnm0000gn/T/pip-build-oh1mgzrd/kivy/kivy/_event.c:14008) 
    File "kivy/_event.pyx", line 1148, in kivy._event.EventObservers._dispatch (/private/var/folders/42/pdwcpzkj0j56rssch8hjpwnm0000gn/T/pip-build-oh1mgzrd/kivy/kivy/_event.c:13537) 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/core/window/__init__.py", line 159, in _on_window_key_down 
    return self.dispatch('on_key_down', keycode, text, modifiers) 
    File "kivy/_event.pyx", line 714, in kivy._event.EventDispatcher.dispatch (/private/var/folders/42/pdwcpzkj0j56rssch8hjpwnm0000gn/T/pip-build-oh1mgzrd/kivy/kivy/_event.c:8119) 
    File "kivy/_event.pyx", line 1224, in kivy._event.EventObservers.dispatch (/private/var/folders/42/pdwcpzkj0j56rssch8hjpwnm0000gn/T/pip-build-oh1mgzrd/kivy/kivy/_event.c:14008) 
    File "kivy/_event.pyx", line 1148, in kivy._event.EventObservers._dispatch (/private/var/folders/42/pdwcpzkj0j56rssch8hjpwnm0000gn/T/pip-build-oh1mgzrd/kivy/kivy/_event.c:13537) 
TypeError: on_keyboard_down() takes 2 positional arguments but 5 were given 

PlayerImage

class PlayerImage(Image): 
    angle = NumericProperty(0) 

    def __init__(self,**kwargs): 
     super(PlayerImage, self).__init__(**kwargs) 
     self.states = {"personred/rest.png/": 0, 
         "person.zip/": 1} 
     self.currentstate = self.states["personred/rest.png/"] 

     self.art = "./rpgArt/" + str(self.currentstate) 
     self._keyboard = Window.request_keyboard(self,None) 
     if not self._keyboard: 
      return 
     self._keyboard.bind(on_key_down=self.on_keyboard_down) 


    def on_keyboard_down(self, keycode): # KEYBOARD FUNC 
     if keycode[1] == "right": 
      self.x += 10 
     if keycode[1] == "left": 
      self.x -= 10 


    def on_touch_down(self, touch): 
     self.currentstate = self.states["person.zip/"] 
     Animation.cancel_all(self) 
     angle = degrees(atan2(touch.y - self.center_y, 
           touch.x - self.center_x)) 

     Animation(center=touch.pos, angle=angle).start(self) 
     self.currentstate = self.states["personred/rest.png/"] 

我的身材:

Builder.load_string(''' 
<PlayerImage>: 
    canvas.before: 
     PushMatrix 
     Rotate: 
      angle: self.angle 
      axis: (0, 0, 1) 
      origin: self.center 
    canvas.after: 
     PopMatrix 
<PlayerImage2>: 
    canvas.before: 
     PushMatrix 
     Rotate: 
      angle: self.angle 
      axis: (0, 0, 1) 
      origin: self.center 
    canvas.after: 
     PopMatrix 
''') 

第二增:

root = Builder.load_string(''' 
    Widget: 
     Widget: 
      PlayerImage: 
       source: './rpgArt/person.zip' 
       allow_stretch: True 
       keep_ratio: True 

    ''') 

回答

1

如果你在 '* ARGS' 你的 'on_keyboard_down' 方法取代 '鍵碼',然後做一個印刷(* ARGS')的方法,你可能會得到關於哪個5個參數傳遞給該方法的線索。

+0

是的,謝謝你,我不得不添加'文字''修飾符等......然後我打印它們! –

相關問題