Page 374 -
P. 374
graphical interface elements
Use pygame to set the volume
Turns out pygame has this functionality built right into its library code via the
set_volume() method.
Take a look at this small example program:
import pygame.mixer
from time import sleep
mixer = pygame.mixer
mixer.init()
track = mixer.Sound("50459_M_RED_Nephlimizer.wav")
print("Play it LOUD, man!")
track.play(loops = -1)
Set the volume to a LOUD
track.set_volume(0.9) setting.
sleep(2)
print("Softly does it ... ")
Set the volume to
track.set_volume(0.1)
sleep(2) a very low setting.
track.stop()
Turn that racket down!
Louder, dude, louder!
When you set the track’s volume to a high value using set_volume(), it’s
the equivalent of cranking up the volume by moving the slider to the right. When
you set it to a low value, that’s like moving the slider to the left.
you are here 4 339