Page 415 -
P. 415

tracks added


                          Pool Puzzle Solution

                          Your job was to take segments from the
                              pool and place them into the blank
                               lines in the code. You could not
                               use the same segment more than
                               once, and you didn’t need to use
                               all the segments. Your goal was to
                               complete the code in hfmix.pyw
                            so that it reads all the tracks from the
                          directory and then adds them to the GUI
                          interface.
                                   from tkinter import *
           You need to talk to the   from sound_panel import *
                                   import pygame.mixer
           operating system, so    import os
           import the “os” module.
                                   app = Tk()
                                   app.title("Head First Mix")
                                                               Get the names of all
                                   mixer = pygame.mixer        the files in the current

                                   mixer.init()                directory.
                   T ake each of the
                                   dirList = os.listdir(".")
                   filenames...
                                   for fname in dirList:

                                       if fname.endswith(".wav"):

        ...and if it ends in “.wav”...          panel = SoundPanel(app, mixer, fname)

                                           panel.pack()

                 ...create a       def shutdown():
                  SoundPanel() and add     track.stop()
                  it to the GUI.          app.destroy()
                                   app.protocol("WM_DELETE_WINDOW", shutdown)
                                   app.mainloop()




                 This wasn’t
                 needed.






                            “50459_M_RED_Nephlimizer.wav”







           380    Chapter 10
   410   411   412   413   414   415   416   417   418   419   420