pygame-menu icon indicating copy to clipboard operation
pygame-menu copied to clipboard

AttributeError when changing rangeslider value with an USB gamepad

Open derUli opened this issue 1 year ago • 5 comments

Environment information Describe your environment information, such as:

  • OS: Windows 11
  • python version: 3.11.7
  • pygame version: pygame-ce 2.4.0
  • pygame-menu version: 4.4.3

Describe the bug pygame-menu crashes when changing a rangeslider's value using a controller.

  File "C:\Users\useraccount\AppData\Roaming\Python\Python311\site-packages\pygame_menu\menu.py", line 3027, in mainloop
    self.update(pygame.event.get())
  File "C:\Users\useraccount\AppData\Roaming\Python\Python311\site-packages\pygame_menu\menu.py", line 2566, in update
    selected_widget.update_menu(events)
  File "C:\Users\useraccount\AppData\Roaming\Python\Python311\site-packages\pygame_menu\widgets\core\widget.py", line 2762, in update_menu
    return self.update(events)
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\useraccount\AppData\Roaming\Python\Python311\site-packages\pygame_menu\widgets\widget\rangeslider.py", line 962, in update
    if self._left_right(event, True):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\useraccount\AppData\Roaming\Python\Python311\site-packages\pygame_menu\widgets\widget\rangeslider.py", line 880, in _left_right
    if event.key not in self._keyrepeat_counters:
       ^^^^^^^^^
AttributeError: 'pygame.event.Event' object has no attribute 'key'

To Reproduce Just make a pygame-menu with a rangeslider. Run the app and try to change the value using the left stick or arrow keys of an USB gaming controller.

Expected behavior Should change the value like it does when pressing left arrow or right arrow on a PC keyboard.

Additional context I am using an Xbox 360 style USB gaming controller. But it seems to be a general error not related to specific hardware.

derUli avatar Feb 17 '24 10:02 derUli

This is also impacting me and I'm unfortunately having to use a selector instead. The surrounding code seems to suggest it supports gamepads but then inside the _left_right method we see it assume that a key is pressed so probably just never got updated.

fommil avatar May 29 '25 15:05 fommil

Interesting. Can you test the issue with the latest version? If that does not work, I will check it for the selector this weekend.

Please feel free to PR if you want to contribute and have a solution

ppizarror avatar May 29 '25 15:05 ppizarror

thanks @ppizarror I am on 4.5.2 and that's the latest pip will give me. Is there some way I can force it to update? I'm tying my pygame to the version in debian 13 and raspberry pi as that's my final target (2.6.1). I'm not using pipenv because it basically doesn't work between debian and rpi because of hash code mismatches. There doesn't seem to be a debian build of pygame_menu btw, which is a shame because I think the raspberry pi is an amazing target for this.

fommil avatar May 30 '25 22:05 fommil

@fommil I think this is because I dropped support for Python 3.6 and 3.7, as they are no longer supported. I suggest updating at least to Python 3.8. This decision was made because even the GitHub integration tool dropped 3.7, so I can no longer provide tests for such versions.

ppizarror avatar May 31 '25 01:05 ppizarror

debian uses Python 3.13.3

fommil avatar May 31 '25 20:05 fommil