最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

利用Python編寫(xiě)本地音樂(lè)播放器

 更新時(shí)間:2022年03月28日 08:31:03   作者:驟雨南山下  
這篇文章主要介紹了利用Python編寫(xiě)本地音樂(lè)播放器,主要以分享完整源碼展開(kāi)文章內(nèi)容,具有一的參考價(jià)值,需要的小伙伴可以參考一下

先上完整代碼:

修改文件夾路徑即可運(yùn)行

# -*- encoding: utf-8 -*-
'''
@Description: ? ? ? :
@Date ? ? :2022/03/24 17:43:26
@Author ? ? ?:驟&雨
@version ? ? ?:1.0
'''
#導(dǎo)入相關(guān)庫(kù)文件
import os
import tkinter
import tkinter.filedialog
import random
import time
import threading
import pygame

from asyncio.base_tasks import _task_print_stack
from cProfile import label
from email import header
from functools import total_ordering
from importlib import find_loader
from logging import root
from mimetypes import init
from re import X
from turtle import width
from matplotlib.pyplot import pause
from scipy import rand

#設(shè)置文件夾路徑
folder = r'C:\Users\Administrator\Desktop\Python\Python Code\TiquMusicFromVedio'


"""
@description ?: 音樂(lè)播放,默認(rèn)播放文件夾內(nèi)的所有mp3文件
---------
@param ?:
-------
@Returns ?:
-------
"""
def play():
? ? global folder
? ? music =[folder+'\\'+music for music in os.listdir(folder)\
? ? ? ? if music.endswith(('.mp3','.wav','.ogg'))]
? ? total = len(music)
? ? #初始化混音器設(shè)備
? ? pygame.mixer.init()
? ? while playing:
? ? ? ? if not pygame.mixer.music.get_busy():
? ? ? ? ? ? #隨機(jī)播放一首歌曲
? ? ? ? ? ? nextMusic = random.choice(music)
? ? ? ? ? ? pygame.mixer.music.load(nextMusic.encode())
? ? ? ? ? ? #播放一次
? ? ? ? ? ? pygame.mixer.music.play(1)
? ? ? ? ? ? musicName.set('playing.......'+nextMusic)
? ? ? ? else:
? ? ? ? ? ? time.sleep(0.3)

root = tkinter.Tk()
root.title('音樂(lè)播放器')
root.geometry('700x80+400+300')
root.resizable(False,False)

#關(guān)閉程序時(shí)執(zhí)行的代碼
def closeWindow():
? ? global playing
? ? playing = False
? ? try:
? ? ? ? pygame.mixer.music.stop()
? ? ? ? pygame.mixer.quit()
? ? except:
? ? ? ? pass
? ? root.destroy()
root.protocol('WM_DELETE_WINDOW',closeWindow)
pause_resume=tkinter.StringVar(root,value = 'NotSet')
playing = False

#播放按鈕
def ?buttonPlayClick():
? ? global folder
? ? if not folder:
? ? ? ? folder = tkinter.filedialog.askdirectory()
? ? if not folder:
? ? ? ? return
? ? global playing
? ? playing = True


? ? #創(chuàng)建一個(gè)線(xiàn)程來(lái)播放音樂(lè)
? ? t = threading.Thread(target=play)
? ? t.start()
? ? #根據(jù)情況禁用或啟用相應(yīng)按鈕
? ? buttonPlay['state'] = 'disabled'
? ? buttonStop['state'] = 'normal'
? ? buttonPause['state'] = 'normal'
? ? buttonNext['state'] = 'normal'
? ? pause_resume.set('Pause')
buttonPlay = tkinter.Button(root,text = 'Play',command=buttonPlayClick)
buttonPlay.place(x=20,y=10,width=50,height=20)

#終止按鈕
def buttonStopClick():
? ? global playing
? ? playing = False
? ? pygame.mixer.music.stop()
? ? musicName.set('暫時(shí)沒(méi)有播放音樂(lè)')
? ? buttonPlay['state'] = 'normal'
? ? buttonStop['state'] = 'disabled'
? ? buttonPause['state'] = 'disabled'
buttonStop = tkinter.Button(root,text='Stop',command=buttonStopClick)
buttonStop.place(x=80,y=10,width=50,height=20)
buttonStop['state']='disabled'

#暫停與恢復(fù) 復(fù)用按鈕
def buttonPauseClick():
? ? global playing
? ? if pause_resume.get()=='Pause':
? ? ? ? #playing = False
? ? ? ? pygame.mixer.music.pause()
? ? ? ? pause_resume.set('Resume')
? ? elif pause_resume.get()=='Resume':
? ? ? ? #playing = True
? ? ? ? pygame.mixer.music.unpause()
? ? ? ? pause_resume.set('Pause')
buttonPause = tkinter.Button(root,textvariable=pause_resume,command=buttonPauseClick)
buttonPause.place(x=140,y=10,width=50,height=20)
buttonPause['state']='disabled'

#下一首
def buttonNextClick():
? ? global playing
? ? playing = False
? ? pygame.mixer.music.stop()
? ? pygame.mixer.quit()
? ? buttonPlayClick()
buttonNext = tkinter.Button(root,text='Next',command=buttonNextClick)
buttonNext.place(x=200,y=10,width=50,height=20)
buttonNext['state']='disabled'

musicName = tkinter.StringVar(root,value='暫時(shí)沒(méi)有播放音樂(lè)!')
labelName = tkinter.Label(root,textvariable=musicName)
labelName.place(x=0,y=40,width=700,height=20)

#啟動(dòng)消息循環(huán)
root.mainloop()

運(yùn)行結(jié)果如下:

到此這篇關(guān)于利用Python編寫(xiě)本地音樂(lè)播放器的文章就介紹到這了,更多相關(guān)Python編寫(xiě)音樂(lè)播放器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python腳本框架webpy的url映射詳解

    python腳本框架webpy的url映射詳解

    這篇文章主要為大家介紹了python腳本框架web.py的url映射的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步
    2021-11-11
  • python微信公眾號(hào)之關(guān)注公眾號(hào)自動(dòng)回復(fù)

    python微信公眾號(hào)之關(guān)注公眾號(hào)自動(dòng)回復(fù)

    這篇文章主要為大家詳細(xì)介紹了python微信公眾號(hào)之關(guān)注公眾號(hào)自動(dòng)回復(fù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • Python中的嵌套循環(huán)詳情

    Python中的嵌套循環(huán)詳情

    這篇文章主要介紹了Python中的嵌套循環(huán)詳情,嵌套循環(huán)就是一個(gè)外循環(huán)的主體部分是一個(gè)內(nèi)循環(huán)。內(nèi)循環(huán)或外循環(huán)可以是任何類(lèi)型,下列詳情介紹內(nèi)容,需要的朋友可以參考一下
    2022-03-03
  • Python爬蟲(chóng)代理IP池實(shí)現(xiàn)方法

    Python爬蟲(chóng)代理IP池實(shí)現(xiàn)方法

    在公司做分布式深網(wǎng)爬蟲(chóng),搭建了一套穩(wěn)定的代理池服務(wù),為上千個(gè)爬蟲(chóng)提供有效的代理,保證各個(gè)爬蟲(chóng)拿到的都是對(duì)應(yīng)網(wǎng)站有效的代理IP,從而保證爬蟲(chóng)快速穩(wěn)定的運(yùn)行,所以就想利用一些免費(fèi)的資源搞一個(gè)簡(jiǎn)單的代理池服務(wù)。
    2017-01-01
  • 常見(jiàn)的python正則用法實(shí)例講解

    常見(jiàn)的python正則用法實(shí)例講解

    這篇文章為大家詳細(xì)主要介紹了常見(jiàn)的python正則用法實(shí)例,列舉Python正則表達(dá)式的幾種匹配用法,感興趣的小伙伴們可以參考一下
    2016-06-06
  • 使用TensorBoard進(jìn)行超參數(shù)優(yōu)化的實(shí)現(xiàn)

    使用TensorBoard進(jìn)行超參數(shù)優(yōu)化的實(shí)現(xiàn)

    這篇文章主要介紹了使用TensorBoard進(jìn)行超參數(shù)優(yōu)化的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • 簡(jiǎn)單有效上手Python3異步asyncio問(wèn)題

    簡(jiǎn)單有效上手Python3異步asyncio問(wèn)題

    這篇文章主要介紹了簡(jiǎn)單有效上手Python3異步asyncio問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • Python使用eval函數(shù)解析和執(zhí)行字符串

    Python使用eval函數(shù)解析和執(zhí)行字符串

    在Python中,eval函數(shù)是一個(gè)非常強(qiáng)大的函數(shù),它可以將字符串作為代碼進(jìn)行解析和執(zhí)行,本文主要介紹了如何使用eval函數(shù)解析和執(zhí)行字符串,需要的可以了解下
    2024-01-01
  • Django 實(shí)現(xiàn)xadmin后臺(tái)菜單改為中文

    Django 實(shí)現(xiàn)xadmin后臺(tái)菜單改為中文

    今天小編就為大家分享一篇Django 實(shí)現(xiàn)xadmin后臺(tái)菜單改為中文,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-11-11
  • Python函數(shù)式編程實(shí)現(xiàn)登錄注冊(cè)功能

    Python函數(shù)式編程實(shí)現(xiàn)登錄注冊(cè)功能

    這篇文章主要為大家詳細(xì)介紹了Python函數(shù)式編程實(shí)現(xiàn)登錄注冊(cè)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-02-02

最新評(píng)論

阿图什市| 从江县| 封丘县| 瓮安县| 固镇县| 资兴市| 吉木萨尔县| 沈阳市| 镇康县| 枣强县| 东台市| 贵溪市| 孟津县| 吉安县| 太仓市| 南宁市| 金乡县| 宁城县| 银川市| 进贤县| 桓台县| 东丽区| 天水市| 新蔡县| 民乐县| 浪卡子县| 惠州市| 无为县| 沙洋县| 海盐县| 东辽县| 靖安县| 当雄县| 石河子市| 凭祥市| 汤原县| 华安县| 通辽市| 故城县| 湾仔区| 九龙城区|