Adding sounds
A sound engine can be created using the Sound
class. The sound engine
can be customized by setting a sound file to several sounds defined by a type.
Example:
import pygame_menu
from pygame_menu import sound
engine = sound.Sound()
engine.set_sound(sound.SOUND_TYPE_CLICK_MOUSE, '/home/me/click.ogg')
engine.set_sound(sound.SOUND_TYPE_OPEN_MENU, '/home/me/open.ogg')
menu = pygame_menu.Menu(...)
menu.set_sound(engine, recursive=True) # Apply on menu and all sub-menus
Sound types are the following:
Type |
Description |
---|---|
|
Mouse click |
|
Touch click |
|
A menu is closed |
|
Generic error |
|
Generic event |
|
Error generated by user |
|
User type a key |
|
User deletes with a key |
|
A menu is opened |
|
A widget is selected |
Sound engine class.
- Parameters:
allowedchanges (
int
) – Convert the samples at runtime, only in pygame>=2.0.0buffer (
int
) – Buffer sizechannels (
int
) – Number of channelsdevicename (
str
) – Device nameforce_init (
bool
) – Force mixer init with new parametersfrequency (
int
) – Frequency of soundssize (
int
) – Size of samplesound_id (
str
) – Sound IDuniquechannel (
bool
) – Force the channel to be unique, this is set at the object creation momentverbose (
bool
) – Enable/disable verbose mode (warnings/errors)
Return a copy of the object.
- Return type:
- Returns:
Sound copied
Return the channel of the sound engine.
- Return type:
- Returns:
Sound engine channel
Return the channel information.
Load the example sounds provided by the package.
Pause the channel.
- Return type:
- Returns:
Self reference
Play click mouse sound.
- Return type:
- Returns:
Self reference
Play click touch sound.
- Return type:
- Returns:
Self reference
Play close Menu sound.
- Return type:
- Returns:
Self reference
Play error sound.
- Return type:
- Returns:
Self reference
Play event sound.
- Return type:
- Returns:
Self reference
Play event error sound.
- Return type:
- Returns:
Self reference
Play key addition sound.
- Return type:
- Returns:
Self reference
Play key deletion sound.
- Return type:
- Returns:
Self reference
Play open Menu sound.
- Return type:
- Returns:
Self reference
Play widget selection sound.
- Return type:
- Returns:
Self reference
Link a sound file to a sound type.
Stop the channel.
- Return type:
- Returns:
Self reference
Unpause channel.
- Return type:
- Returns:
Self reference