《Head First Programming》---python 10_GUI Mixer2
来源:互联网 发布:车贷app管理系统源码 编辑:程序博客网 时间:2024/05/22 17:29
1.sound_panel模块
from tkinter import *import pygame.mixerclass SoundPanel(Frame): def __init__(self, app, mixer, sound_file): Frame.__init__(self, app) #这里用到了tkinter的Frame self.track = mixer.Sound(sound_file) self.track_playing = IntVar() track_button = Checkbutton(self, variable = self.track_playing, command = self.track_toggle, text = sound_file ) track_button.pack(side = LEFT) self.volume = DoubleVar() self.volume.set(self.track.get_volume()) volume_scale = Scale(self, variable = self.volume, from_ = 0.0, to = 1.0, resolution = 0.1, command = self.change_volume, label = 'Volume', orient = HORIZONTAL ) volume_scale.pack(side = RIGHT) def track_toggle(self): if self.track_playing.get() == 1:#囧,刚开始.get()未写一直没有声音 self.track.play(loops = -1) #循环播放至结束 else: self.track.stop() def change_volume(self, v): self.track.set_volume(self.volume.get())
2.hfmix主程序
from tkinter import *from sound_panel import *import pygame.mixerimport os #与操作系统相关的模块app = Tk()app.title("Head Firs Mix2")mixer = pygame.mixermixer.init()dirList = os.listdir(".")for fname in dirList: if fname.endswith(".wav"): panel = SoundPanel(app, mixer, fname) panel.pack()def shutdown(): mixer.stop()#书中这里有问题的,改正为mixer app.destroy()app.protocol("WM_DELETE_WINDOW", shutdown)app.mainloop()
3.运行截图:
0 0
- 《Head First Programming》---python 10_GUI Mixer2
- 《Head First Programming》---python 7_GUI搭建
- 《Head First Programming》---python 9_GUI Mixer
- 《Head First Programming》---python 8 and 8 1/2_GUI, data, exception
- 《Head First Programming》---python 3_函数
- 《Head First Programming》---python 1_开始编码
- 《Head First Programming》---python 2_文本数据
- 《Head First Programming》---python 5_哈希与数据库
- 《Head First Programming》---python 6_模块化编程
- Head First Python
- Head First Python 读书笔记
- 《Head First Programming》---python 4_文件和数组中的数据
- Head First HTML5 Programming 学习笔记
- 《head first html5 programming》html5开始了
- 《Head First Python》学习笔记
- Head First Python笔记01
- head first python 读书记录
- head first python /chapter7 web
- win8快捷键剪辑
- 广州电子路考视频发布 2014广州电子路考考点
- oracle行列转换总结
- tomcat 启动不了
- IT痴汉的工作现状8-三思而后行
- 《Head First Programming》---python 10_GUI Mixer2
- Timus 2011. Long Statement 排列组合的运用
- 防守阵地 I
- The serializable class Proname does not declare a static final serialVersionUID field of type long
- 路考步骤七步走 科目三考试一定没问题!
- 新驾考科目三-2014新交规科目三大路考试技巧
- 分享,创造的灵魂——分享广东省”英课“计划青年教师信息化新课堂计划试验课程申报表
- 广州驾校考试实际道路考试注意事项(图)
- 排序算法之堆排序