Page 407 -
P. 407
initializer constructed
Code Magnets Solution
We’ve started to create the initializer code for you, but there are still a few
parts missing. See if you can work out where the missing code fragments
fit. Here is the code that creates a SoundPanel() object. You were
asked to position the code magnets properly to complete the method:
Each SoundPanel()
object has its own track.
def __init__(self, app, mixer, sound_file):
That’s a double Frame.__init__(self, app)
underscore at track = mixer.Sound(sound_file)
either side of self.
the word “init”. Each SoundPanel() object has its
self. track_playing = IntVar() own checkbox.
self
track_playing
self.
track_button = Checkbutton( , variable = ,
command = self.track_toggle, text = sound_file)
track_button.pack(side = LEFT)
self. volume = DoubleVar()
self.volume.set(track.get_volume())
volume_scale = Scale( , variable = self.volume, from_ = 0.0, to = 1.0,
self
Each SoundPanel() self. change_volume
resolution = 0.1, command = ,
object has its own slider.
label = "Volume", orient = HORIZONTAL)
volume_scale.pack(side = RIGHT)
class = methods + data
The SoundPanel() class has methods that define the behavior
that it implements. In addition to the methods, the class also
has to detail the data that it holds. For the SoundPanel()
class, this data is made up from three things: the track to play,
its checkbox, and its associated slider.
372 Chapter 10

