Page 390 -
P. 390

custom widgets and classes




           Begin by importing    from tkinter import *
           the libraries you
           need to use in this   import pygame
          module.
         Create a new function   def create_gui(app, mixer, sound_file):
         that contains the GUI-        def track_toggle():
         creating code from the
         current program.                      if track_playing.get() == 1:
                                                      track.play(loops = -1)

                                               else:

                                                      track.stop()



                                       def change_volume(v):

                                               track.set_volume(volume.get())




             All of this code is part        track = mixer.Sound(sound_file)
             of the function, so it
             needs to be indented.         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)




                                                                                      you are here 4    355
   385   386   387   388   389   390   391   392   393   394   395