第一范文网 - 专业文章范例文档资料分享平台

《Python程序设计》习题与答案

来源:用户分享 时间:2025/5/18 14:10:29 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

import threading class wxGUI(wx.App): def OnInit(self):

frame = wx.Frame(parent=None, title='MP3Player', size=(250,150), pos=(350,350)) panel = wx.Panel(frame, -1)

self.buttonOK = wx.Button(panel, -1, 'Play', pos=(30,60)) self.Bind(wx.EVT_BUTTON, self.OnButtonOK, self.buttonOK) self.buttonOK.Enabled = True

self.buttonCancel = wx.Button(panel, -1, 'Stop', pos=(120,60)) self.Bind(wx.EVT_BUTTON, self.OnButtonCancel, self.buttonCancel) self.buttonCancel.Enabled = False frame.Show() return True def OnExit(self): try:

self.playing = False

pygame.mixer.music.stop() finally: pass

def play(self):

folder = r'h:\\music'

musics = [folder+'\\\\'+music for music in os.listdir(folder) if music.endswith('.mp3')] total = len(musics)

pygame.mixer.init() while self.playing:

if not pygame.mixer.music.get_busy(): nextMusic = random.choice(musics) pygame.mixer.music.load(nextMusic) pygame.mixer.music.play(1) print 'playing....',nextMusic else:

time.sleep(1)

def OnButtonOK(self, event): self.playing = True

# create a new thread to play music t = threading.Thread(target=self.play) t.start()

self.buttonOK.Enabled = False self.buttonCancel.Enabled = True def OnButtonCancel(self, event): self.playing = False

pygame.mixer.music.stop() self.buttonOK.Enabled = True self.buttonCancel.Enabled = False

app = wxGUI() app.MainLoop()

15.5 运行本章15.4中的代码并查看运行结果。 答:略。

本文档下载自文档之家,www.doczj.com-免费文档分享平台,众多试卷、习题答案、公务员考试、英语学习、法语学习、人力资源管理、电脑基础知识、学习计划、工作计划、工作总结、活动策划、企业管理等文档分类免费下载;乐于分享,共同进步,转载请保留出处:http://www.doczj.com/doc/0b62a12b941ea76e59fa046b.html

搜索更多关于: 《Python程序设计》习题与答案 的文档
《Python程序设计》习题与答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c3fdcc8tqiu7dd7d92wae4uc568cqjj01a1j_7.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top