Advertisement
fmasanori

sound_panel

Nov 9th, 2011
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. from tkinter import *
  2. import pygame.mixer
  3. class SoundPanel(Frame):
  4.     def track_toggle(self):
  5.         if self.track_playing.get() == 1:
  6.             self.track.play(loops = -1)
  7.         else:
  8.             self.track.stop()
  9.     def change_volume(self, v):
  10.         self.track.set_volume(self.volume.get())
  11.  
  12.     def __init__(self, app, mixer, sound_file):
  13.         Frame.__init__(self, app)
  14.         self.track = mixer.Sound(sound_file)
  15.         self.track_playing = IntVar()
  16.         track_button = Checkbutton(self, variable = self.track_playing,
  17.             command = self.track_toggle, text = sound_file)
  18.         track_button.pack(side = LEFT)
  19.         self.volume = DoubleVar()
  20.         self.volume.set(self.track.get_volume())
  21.         volume_scale = Scale(self, variable = self.volume,
  22.             from_ = 0.0, to = 1.0, resolution = 0.1,
  23.             command = self.change_volume,
  24.             label = "Volume", orient = HORIZONTAL)
  25.         volume_scale.pack(side = RIGHT)
  26.  
  27.  
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement