Page 401 -
P. 401

programming class


           A class is a machine for creating objects


           Object oriented programming (OOP) languages (like Python) let you create
           an entirely new kind of object using a class. A class is like a template that you
           use to create new objects.
           Think of the class like a cookie-cutter, and think of the object as the cookie
           that is created based on the class. As all the cookies are created from the same
           cookie cutter, they all have the same characteristics, even though they are
           all individual cookies. When an individual object is created from a class, it’s
           referred to as an instance of that class.

           So, if you can arrange for SoundPanel() to be a class, you can create
           custom widgets as required:




                                         You need a new
                                         SoundPanel() class.


                   SoundPanel


                                               The CLASS creates OBJECTs, which
                                                are INSTANCEs of the class.

















          You need code that creates a new grouped widget in the GUI every time you
           make a call like this:
                                  Use the class to create a new object.


                     panel = SoundPanel(app, mixer, "49119_M_RED_HardBouncer.wav")


           Let’s define a SoundPanel() class.



           366    Chapter 10
   396   397   398   399   400   401   402   403   404   405   406