Head First Programming - hlmix.py

 1 from tkinter import *
 2 import pygame.mixer
 3 
 4 app = Tk()
 5 app.title("Head First Mix")
 6 
 7 mixer = pygame.mixer
 8 mixer.init()
 9 sound_file = "50459_M_RED_Nephlimizer.wav"
10 track = mixer.Sound(sound_file)
11 track_playing = IntVar()
12 
13 def shutdown():
14     track.stop()
15     app.destroy()
16 def track_toggle():
17     if track_playing.get() == 1:
18         track.play(loops = -1)
19     else:
20         track.stop()
21 def change_volume(v):
22     track.set_volume(volume.get())
23 track_button = Checkbutton(app, variable = track_playing, command = track_toggle, text = sound_file)
24 track_button.pack(side = LEFT)
25 volume = DoubleVar()
26 volume.set(track.get_volume())
27 volume_scale = Scale(variable = volume,
28                      from_ = 0.0,
29                      to = 1.0,
30                      resolution = 0.1,
31                      command = change_volume,
32                      label = "Volume",
33                      orient = HORIZONTAL)
34 volume_scale.pack(side = RIGHT)
35 
36 app.protocol("WM_DELETE_WINDOW", shutdown)
37 app.mainloop()

 

posted on 2013-01-07 18:59  mybluecode  阅读(145)  评论(0编辑  收藏  举报