Python音乐播放器

#coding:utf-8
import wx
import mp3play
import os

class MyFrame(wx.Frame):  
    def __init__(self,parent,ID,title):  
        wx.Frame.__init__(self,parent,ID,title,wx.DefaultPosition,wx.Size(270,500),style=wx.DEFAULT_FRAME_STYLE&(~wx.MAXIMIZE_BOX)&(~ wx.RESIZE_BORDER))
        self.SetBackgroundColour("blue")           
        #菜单栏
        menubar=wx.MenuBar()
        file=wx.Menu()
        file.Append(101,u'打开','Open a file')
        file.Append(102,u'退出','Save a file')
        info=wx.Menu()
        menubar.Append(file,u'文件')
        menubar.Append(info,u'关于')
        self.SetMenuBar(menubar) 

        #按钮容器部分
        botton_panel=wx.Panel(self,-1,style=wx.SUNKEN_BORDER)
        wx.Button(botton_panel,0,u'播放',(0,20),(80,30))  
        wx.Button(botton_panel,1,u'暂停',(90,20),(80,30))  
        wx.Button(botton_panel,2,u'停止',(180,20),(80,30))

        
        #事件绑定
        wx.EVT_MENU(self,101, self.OnOpen)
        wx.EVT_MENU(self,102, self.OnExit)
        wx.EVT_BUTTON(botton_panel,0, self.OnPlay)
        wx.EVT_BUTTON(botton_panel,1, self.OnPause)
        wx.EVT_BUTTON(botton_panel,2, self.OnStop)

    def OnOpen(self,event):
   		dialog = wx.FileDialog(self,u"~选择一个mp3文件~",os.getcwd(),style=wx.OPEN,wildcard="*.mp3")
   		if dialog.ShowModal() == wx.ID_OK:
   			self.filename = dialog.GetPath()
   			self.mp3 = mp3play.load(self.filename)
			self.mp3.play()
   			print self.filename
   			print self.mp3.seconds()
   		dialog.Destroy()

        	
    def OnExit(self,event):
     	self.Close()
    def OnPlay(self,event):
    	if self.mp3.ispaused():
    		self.mp3.unpause()
    	if not self.mp3.isplaying():
    		self.mp3.play()
    def OnPause(self,event):
        self.mp3.pause() 
    def OnStop(self,event):
       	self.mp3.stop()
 

class MyApp(wx.App):  
    def OnInit(self): 
        frame=MyFrame(None,-1,u'mp3播放器--BY康彪')  
        frame.Show(True)  
        frame.Centre()
        return 1
 

if __name__=="__main__":
	app = MyApp(0)  
	app.MainLoop()

运行效果:




  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值