Page 399 -
P. 399
frame widgets
A frame widget contains other widgets
Most GUI libraries (including tkinter) let you create custom widgets from a A frame is like...
set of other components, and tkinter includes a special kind of widget called a frame.
a frame. A frame works just like a picture frame, in that it surrounds other
things. It’s rectangular and it can contain other widgets:
In tkinter, a frame is created using Frame(). If you can work out a way to
create a new type of frame (called, say, SoundPanel) that contains the checkbox
and the slider, then you could use code something like this in your program:
Create a new These are the same parameters you
SoundPanel passed to the “create_gui()” method.
widget.
Do this!
panel = SoundPanel(app, mixer, “50459_M_RED_Nephlimizer.wav”)
panel.pack()
panel = SoundPanel(app, mixer, “49119_M_RED_HardBouncer.wav”)
panel.pack() Even though you
haven’t created the
SoundPanel code
yet, let’s replace the
You can add your widget to the calls to create_
GUI using the packer, just like gui() in hfmix.
with all the other widgets. pyw with these lines of
code now. Just don’t try
to run it yet.
This look like a great solution. However, you still have a big problem.
This code uses an entirely new type of object, a whole new kind of
widget that has never existed before. How do you tell the computer to create
something like that, which is effectively a custom GUI object?
How do you convince the computer to create a new
widget each time you call SoundPanel()?
364 Chapter 10

