Python Forum
[PyGame] pygame-manu : using controller buttons to move around menu
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] pygame-manu : using controller buttons to move around menu
I'm using pygame-menu and I want to use buttons on my controller to navigate it. I can't figure it out at all. There's no example available online. Also, I'm using a USB NES controller which does not have it's own mapping. I am not sure what the issue is. I've tried many things but nothing seems to help. The menu can be navigated using the keyboard arrow buttons, but not the controller. The documentation is a little confusing on this.
here is code where I tried to make the controller work. It looked a lot different when I started, but I kept changing things and I could never get it to work. So don't use this as an example for your own code, it's likely way off. I also added a function to be run with the player higs the down button on the menu, but I can't get this working either. Help!

import pygame
import pygame_menu
from pygame_menu import themes
from pygame_menu.controls import Controller

pygame_menu.controls.KEY_BACK = Controller.back
pygame_menu.controls.KEY_APPLY = Controller.apply
pygame_menu.controls.KEY_MOVE_DOWN = Controller.joy_up
pygame_menu.controls.KEY_MOVE_UP = pygame_menu.controls.Controller.joy_up
def goDown():
    print('go Down')
    pygame_menu.controls.KEY_MOVE_DOWN = 1

while True:
    surface = pygame.display.set_mode((600, 400))

    def set_difficulty(value, difficulty):
        # Do the job here !
    def start_the_game():
        # Do the job here !
    # pygame_menu.controls.Controller.joy_axis_x_left()

    menu = pygame_menu.Menu('Welcome', 400, 300,

    menu.add.text_input('Name :', default='John Doe')
    menu.add.selector('Difficulty :', [('Hard', 1), ('Easy', 2)], onchange=set_difficulty)
    menu.add.button('Play', start_the_game)
    menu.add.button('Go Down', goDown)

Not sure, but this post seems like it discusses hookup of USB controller:
Forget about the menu and focus on getting events from the controller. Can you do that? Can you see controller button presses?
import pygame

def pgprint(text):
    text = f"{text}::{pygame.joystick.get_count()}"
    surface = font.render(text, True, "black")
    x = (700 - surface.get_width()) // 2
    y = (100 - surface.get_height()) // 2
    screen.blit(surface, (x, y))

screen = pygame.display.set_mode((700, 100))
font = pygame.font.Font(None, 16)

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to make an image move in relation to another in PYGAME CompleteNewb 1 1,658 Nov-10-2021, 03:38 PM
Last Post: metulburr
  Getting a ship to move in pygame djwilson0495 2 2,587 Dec-09-2020, 11:03 AM
Last Post: djwilson0495
  Pygame - Images As Buttons vman44 3 9,940 Mar-20-2020, 08:13 PM
Last Post: vman44
  [PyGame] Problems w/ controller Zman350x 5 3,282 Oct-29-2019, 10:31 PM
Last Post: Zman350x
  [pygame] Equiping inventory slots with invisible buttons SheeppOSU 6 3,740 Apr-26-2019, 08:45 PM
Last Post: SheeppOSU
  Problems with loading buttons (pygame) SheeppOSU 2 2,463 Apr-12-2019, 08:04 PM
Last Post: SheeppOSU
  Buttons in PyGame mzmingle 4 11,981 Oct-09-2018, 05:19 PM
Last Post: Mekire
  Menus, buttons and other widgets for Pygame Olleus 4 10,506 Apr-17-2017, 11:08 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020