In the following program I don't understand why 'mixer' is given as an argument to the function 'create_gui'. Please explain.

File 1

# imports
from Tkinter import *
from sound_panel import *
import pygame.mixer

# create gui
app = Tk()
app.title("Head First Mix")

# create mixder
mixer = pygame.mixer
mixer.init()

# call functions
create_gui(app, mixer, "50459_M_RED_Nephlimizer.wav")
create_gui(app, mixer, "49119_M_RED_HardBouncer.wav")

def shutdown():
        track.stop()
        app.destroy()
    
app.protocol("WM_DELETE_WINDOW", shutdown)
app.mainloop()

file 2(sound_panel.py)

# this is a module

# imports
from Tkinter import *
import pygame.mixer

# create GUI panel
def create_gui(app, mixer, sound_file):
    def track_toggle():
        if track_playing.get() == 1:
            track.play(loops = -1)
        else:
            track.stop()
            
    def change_volume(v):
        track.set_volume(volume.get())
    
    track = mixer.Sound(sound_file)
    track_playing = IntVar()
    track_button = Checkbutton(app, variable = track_playing,
                               command = track_toggle, text = sound_file)
    track_button.pack(side = LEFT)
    volume = DoubleVar()
    volume.set(track.get_volume())
    volume_scale = Scale(variable = volume, from_ = 0.0, to = 1.0,
                         resolution = 0.1, command = change_volume,
                         label = "Volume", orient = HORIZONTAL)
    volume_scale.pack(side = RIGHT)

The pygame.mixer is a required argument in function
create_gui(app, mixer, sound_file)
where it is used in code line
track = mixer.Sound(sound_file)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.