|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #-*-coding:utf-8-*-
- #file:pyMusicPlayer.py
- #
- import tkinter #导入tkinter模块
- import tkinter.filedialog #导入tkFileDialog模块
- from win32com.client import Dispatch
- class Window:
- def __init__(self):
- self.root = root = tkinter.Tk() #创建窗口
- buttonAdd = tkinter.Button(root,text = 'Add',\
- command = self.add)
- buttonAdd.place(x= 150,y = 15)
- buttonPlay = tkinter.Button(root,text = 'Play',\
- command = self.play)
- buttonPlay.place(x = 200,y = 15)
- buttonPause = tkinter.Button(root,text = 'Pause',\
- command = self.pause)
- buttonPause.place(x = 250,y = 15)
- buttonStop = tkinter.Button(root,text = 'Stop',\
- command = self.stop)
- buttonStop.place(x = 300,y = 15)
- buttonNext = tkinter.Button(root,text = 'Next',\
- command = self.next)
- buttonNext.palce(x = 350,y = 15)
- frame = tkinter.Frame(root,bd = 2)
- self.playList = tkinter.Text(frame)
- scrollbar = tkinter.Scrollbar(frame)
- scrollbar.config(command = self.playList.yview)
- self.playList.pack(side = tkinter.LEFT)
- scrollbar.pack(side = tkinter.RIGHT,fill = tkinter.Y)
- frame.place(y = 50)
- self.wmp = Dispatch('WMPlayer.OCX') #绑定WMPlayer.OCX
- def MainLoop(self): #进入消息循环
- self.root.minsize(510.380)
- self.root.maxsize(510,380)
- self.root.mainloop()
- def add(self): #添加播放文件
- file = tkinter.filedialog.askopenfilename(\
- title = 'Python Music Player',\
- filetypes = [('MP3','*.mp3'),('WMA','*.wma'),\
- ('WAV','*.wav')])
- if file:
- media = self.wmp.newMedia(file)
- self.wmp.currentPlaylist.appendItem(media)
- self.playList.inser(tkinter.END,file + '\n')
- def play(self):
- self.wmp.controls.play() #播放文件
- def pause(self):
- self.wmp.controls.pause() #暂停
- def next(self):
- self.wmp.controls.next() #下一首
- def stop(self):
- self.wmp.controls.stop() #停止
- window = Window()
- window.MainLoop()
复制代码
缩进都没有问题,只是提示倒数第二行的代码有错误,请帮我看一下好吗
|
|