欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python3音樂播放器簡(jiǎn)單實(shí)現(xiàn)代碼

 更新時(shí)間:2020年04月20日 11:26:27   作者:jinx88  
這篇文章主要為大家詳細(xì)介紹了python3音樂播放器簡(jiǎn)單實(shí)現(xiàn)代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了python3音樂播放器的關(guān)鍵代碼,供大家參考,具體內(nèi)容如下

from tkinter import *
from traceback import *
from win32com.client import Dispatch
import time,eyed3,threading
 
name = []
 
def openfile(index = [1]):
 global total,name
  
 filenames = filedialog.askopenfilenames(title = "音樂播放器",filetypes =[("mp3文件","*.mp3"),("WMA文件","*.wma"),("WAV文件","*.wav")])
 if filenames:
  for i in range(len(filenames)):
   media = wmp.newMedia(filenames[i])
   wmp.currentPlaylist.appendItem(media)
   
   print(filenames[i])
   
   coco = eyed3.load(filenames[i])#eyed3模塊讀取mp3信息
   total = int(coco.info.time_secs)
   minute = int(coco.info.time_secs)//60
   sec = int(coco.info.time_secs)%60
   length = int(coco.info.time_secs)
   
   name = filenames[i].split("/")
   
   i =index[-1]
   list_name.insert(END,str(i)+"."+name[-1])
   list_name.insert(END," "*6)
   if sec >=10:
    list_name.insert(END,"0%d:%d" %(minute,sec)+ "\n")
   else:
    list_name.insert(END,"0%s:0%d" %(minute,sec)+ "\n")
   i = i +1
   index.append(i)
def play(event = None):
 #root.title("%s" % name[-1]),使用wmp.currentMedia.name更好,在per函數(shù)中
 per_thread = threading.Thread(target = per)
 per_thread.daemnon = True
 wmp.controls.play()
 per_thread.start()
 #print(wmp.currentMedia.duration)#放到暫停那里居然可以用,而這里不行
 
  
def per():
 global total
 while wmp.playState !=1:
  progress_scal.set(int(wmp.controls.currentPosition))
  progress_scal.config(label = wmp.controls.currentPositionString)
  progress_scal.config(to = total,tickinterval = 50)
  time.sleep(1)
  root.title("%s" % wmp.currentMedia.name)
  
def stop():
 wmp.controls.stop()
def pause(event = None):
 wmp.controls.pause()
 
def uselist():
  pass
def fullscr():
  pass
def exitit():
 root.destroy()
def Previous_it():
 wmp.controls.previous()
def Next_it():
 wmp.controls.next()
def Volume_ctr(none):
 wmp.settings.Volume = vio_scale.get()
def Volume_add(i=[0]):
 wmp.settings.Volume =wmp.settings.Volume+5
 i.append(wmp.settings.Volume)
 vio_scale.set(wmp.settings.Volume)
def Volume_minus(i=[0]):
 wmp.settings.Volume = wmp.settings.Volume -5
 i.append(wmp.settings.Volume)
 vio_scale.set(wmp.settings.Volume)
def Scale_ctr(none):
 
 wmp.controls.currentPosition = var_scale.get()
 print(wmp.currentMedia.duration)
def Clear_list():
 wmp.currentPlaylist.clear()
 list_name.delete(1.0,END)
 name = []
 index = []
def List_random():
 wmp.settings.setMode("shuffle",True)
 play()
def List_loop():
 wmp.settings.setMode("loop",True)
 play()
  
root =Tk()
wmp = Dispatch("WMPlayer.OCX")
 
canvas = Canvas(root,width =150,height = 100,bg = "blue")
filename = PhotoImage(file = "girl.gif")
image =canvas.create_image((0,0),image = filename)
canvas.place(x=0,y=0)
canvas.coords(image,79,50)
canvas.grid(row =0,column = 0,sticky = "nw",rowspan =2)
 
 
progress_lab = LabelFrame(root,text = "播放進(jìn)度")
progress_lab.grid(row =2,column =0,sticky = "we",rowspan = 2)
var_scale = DoubleVar()
progress_scal = Scale(progress_lab,orient = HORIZONTAL,showvalue = 0,length =180,variable = var_scale)
#progress_scal.bind("<Button-1>",pause)
#progress_scal.bind("")
#progress_scal.bind("<ButtonRelease-1>",play)
progress_scal.grid(row =3,column =0)
 
modee_lab = LabelFrame(root,text = "播放模式")
modee_lab.grid(row =4,column =0,rowspan =4,sticky = "ws")
var_mode = IntVar()
randomradio = Radiobutton(modee_lab,variable = var_mode,value = 1,text ="隨機(jī)播放",command =List_random )
randomradio.grid(row =4,column =2)
inturnradio = Radiobutton(modee_lab,variable = var_mode,value =2,text= "順序播放",command = play)
inturnradio.grid(row=4,column =3)
alloop = Radiobutton(modee_lab,variable = var_mode,value =2,text = "全部循環(huán)播放",command = List_loop)
alloop.grid(row =5,column = 2)
sinloop = Radiobutton(modee_lab,variable = var_mode,value =3,text = "單曲循環(huán)播放")
sinloop.grid(row =5,column =3)
previous_play = Button(modee_lab,text = "上一曲",height =1,command = Previous_it)
previous_play.grid(row =6,column =2,rowspan =2,pady =5)
next_play = Button(modee_lab,text = "下一曲",height =1,command = Next_it)
next_play.grid(row =6,column =3,rowspan =2,pady =5)
 
var_volume = IntVar()
vioce_lab = LabelFrame(root,text = "音量控制")
vioce_lab.grid(row =8,column =0,sticky = "wes")
vio_scale = Scale(vioce_lab,orient = HORIZONTAL,length =170,variable = var_volume,command =Volume_ctr)
vio_scale.set(30)
vio_scale.grid(row =8,column =0)
vio_plus = Button(vioce_lab,width =8,text = "增加音量+",command =Volume_add)
vio_plus.grid(row =9,column =0,sticky = "w")
vio_minus = Button(vioce_lab,width =8,text ="減少音量-",command = Volume_minus)
vio_minus.grid(row =9,column =0,sticky ="e")
 
ctr_lab = LabelFrame(root,text = "播放控制",height =130)
ctr_lab.grid(row =0,column =1,rowspan =12,sticky = "ns")
btn_open = Button(ctr_lab,text ="打開音樂文件",width =10,command = openfile)
btn_open.grid(row=0,column =1)
btn_play = Button(ctr_lab,text ="播放",width =10,command = play)
btn_play.grid(row =1,column =1,pady =5)
btn_stop = Button(ctr_lab,text ="停止",width =10,command = stop)
btn_stop.grid(row =2,column =1,pady =5)
btn_pause = Button(ctr_lab,text ="暫停",width =10,command = pause)
btn_pause.grid(row =3,column =1,pady =5)
 
btn_playlist = Button(ctr_lab,text ="新建播放列表",width =10,command = uselist)
btn_playlist.grid(row =4,column =1,pady =5)
 
 
listimport = Button(ctr_lab,width =10,text = "導(dǎo)入列表")
listimport.grid(row =6,column =1,sticky ="nw",pady =5)
listexport = Button(ctr_lab,width =10,text = "導(dǎo)出列表")
listexport.grid(row =7,column =1,sticky = "nw",pady =5)
listdel_all = Button(ctr_lab,width =10,text = "清空列表",command = Clear_list)
listdel_all.grid(row =8,column =1,sticky ="nw",pady =5)
listdel_sel= Button(ctr_lab,width =10,text = "刪除歌曲")
listdel_sel.grid(row =12,column =1,sticky = "nw",pady =5)
savelist_btn = Button(ctr_lab,text = "保存為列表")
savelist_btn.grid(row=9,column =1)
min_btn = Button(ctr_lab,text = "最小化窗口",command = root.iconify)
min_btn.grid(row =13,column =1)
 
time_lab= Label(root,width =20,height =2,text ="現(xiàn)在時(shí)間為:")
time_lab.grid(row =12,column =0,sticky = "nw",pady =5)
time_text= Text(root,width =30,height =3,foreground ="green")
time_text.grid(row =10,column =0,sticky = "nw",pady =5)
 
list_name = Text(root,height =18,width =110)
list_name.grid(row =0,column =2,sticky = "n",rowspan =6)
 
 
root.mainloop()

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)python程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • python實(shí)現(xiàn)各進(jìn)制轉(zhuǎn)換的總結(jié)大全

    python實(shí)現(xiàn)各進(jìn)制轉(zhuǎn)換的總結(jié)大全

    這篇文章主要給大家總結(jié)了python實(shí)現(xiàn)各進(jìn)制轉(zhuǎn)換的相關(guān)資料,其中包括字符串與十六進(jìn)制轉(zhuǎn)換、內(nèi)置函數(shù)hex()與進(jìn)制互轉(zhuǎn)等相關(guān)內(nèi)容,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2017-06-06
  • Python3批量移動(dòng)指定文件到指定文件夾方法示例

    Python3批量移動(dòng)指定文件到指定文件夾方法示例

    這篇文章主要給大家介紹了關(guān)于Python3批量移動(dòng)指定文件到指定文件夾的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Python3具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • Python常用數(shù)據(jù)類型之列表使用詳解

    Python常用數(shù)據(jù)類型之列表使用詳解

    列表是Python中的基礎(chǔ)數(shù)據(jù)類型之一,其他語(yǔ)言中也有類似于列表的數(shù)據(jù)類型,比如js中叫數(shù)組,他是以[ ]括起來(lái),每個(gè)元素以逗號(hào)隔開,而且他里面可以存放各種數(shù)據(jù)類型。本文將通過示例詳細(xì)講解列表的使用,需要的可以參考一下
    2022-04-04
  • Python多進(jìn)程池 multiprocessing Pool用法示例

    Python多進(jìn)程池 multiprocessing Pool用法示例

    這篇文章主要介紹了Python多進(jìn)程池 multiprocessing Pool用法,結(jié)合實(shí)例形式分析了多進(jìn)程池 multiprocessing Pool相關(guān)概念、原理及簡(jiǎn)單使用技巧,需要的朋友可以參考下
    2018-09-09
  • python中的正則表達(dá)式,貪婪匹配與非貪婪匹配方式

    python中的正則表達(dá)式,貪婪匹配與非貪婪匹配方式

    這篇文章主要介紹了python中的正則表達(dá)式,貪婪匹配與非貪婪匹配方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • 分享Python?的24個(gè)編程超好用技巧

    分享Python?的24個(gè)編程超好用技巧

    這篇文章主要給大家分享Python?的24個(gè)編程超好用技巧,下面分享一些python技巧和?tips,這些技巧將根據(jù)其首字母按?A-Z?的順序進(jìn)行展示,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-02-02
  • python三引號(hào)如何輸入

    python三引號(hào)如何輸入

    在本篇文章里小編給大家整理的是關(guān)于python三引號(hào)輸入方法及相關(guān)實(shí)例,需要的朋友們可以學(xué)習(xí)下。
    2020-07-07
  • 使用Flask獲取請(qǐng)求參數(shù)的方式總結(jié)

    使用Flask獲取請(qǐng)求參數(shù)的方式總結(jié)

    在 Flask 中,可以從 request 對(duì)象中獲取各種類型的參數(shù),這篇文章為大家整理了一些常見的獲取參數(shù)的方式及示例代碼,感興趣的小伙伴可以參考一下
    2025-04-04
  • Python如何讀取、寫入CSV數(shù)據(jù)

    Python如何讀取、寫入CSV數(shù)據(jù)

    這篇文章主要介紹了Python如何讀寫CSV數(shù)據(jù),文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-07-07
  • python threading模塊的使用指南

    python threading模塊的使用指南

    python的thread模塊是底層的模塊,python的threading模塊是對(duì)thread做了一些包裝的,可以更加方便的被使用。本文詳細(xì)的講述了threading模塊的用法
    2021-06-06

最新評(píng)論