ppizarror / pygame-menu

A menu for pygame. Simple, and easy to use
https://pygame-menu.readthedocs.io/
Other
555 stars 141 forks source link

how to get the main menu object inside submenu? #423

Closed MeldyTheCoder closed 1 year ago

MeldyTheCoder commented 1 year ago

Environment information Describe your environment information, such as:

I need to adjust the sound volume for all menus, including the main one. The volume settings menu is a child of the general settings, and the general settings menu is a child of the main menu.

That is: Main Menu -> Settings Menu -> Volume Settings Menu.

How do I apply the settings for the main menu from the child menu?

ppizarror commented 1 year ago

Hi, to set the souds please take a loot at https://pygame-menu.readthedocs.io/en/4.2.8/_source/add_sounds.html

In particular, you can add a custom function to "Volume Settings Menu". When creating the main menu, store that to a variable, therefore:

engine = sound.Sound()
menu = pygame_menu.Menu(...)
submenu = ...

def update_sound(name):
   menu.set_sound(engine, recursive=True)  # Apply on menu and all sub-menus

submenu.add.button('Change sound', update_sound)

Using the menu references, you can do anything you want :) Greetings