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

利用Python編寫本地音樂播放器

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

先上完整代碼:

修改文件夾路徑即可運行

# -*- encoding: utf-8 -*-
'''
@Description: ? ? ? :
@Date ? ? :2022/03/24 17:43:26
@Author ? ? ?:驟&雨
@version ? ? ?:1.0
'''
#導(dǎo)入相關(guān)庫文件
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 ?: 音樂播放,默認(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():
? ? ? ? ? ? #隨機播放一首歌曲
? ? ? ? ? ? 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('音樂播放器')
root.geometry('700x80+400+300')
root.resizable(False,False)

#關(guān)閉程序時執(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)建一個線程來播放音樂
? ? 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('暫時沒有播放音樂')
? ? 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='暫時沒有播放音樂!')
labelName = tkinter.Label(root,textvariable=musicName)
labelName.place(x=0,y=40,width=700,height=20)

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

運行結(jié)果如下:

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

相關(guān)文章

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

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

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

    python微信公眾號之關(guān)注公眾號自動回復(fù)

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

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

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

    Python爬蟲代理IP池實現(xiàn)方法

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

    常見的python正則用法實例講解

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

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

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

    簡單有效上手Python3異步asyncio問題

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

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

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

    Django 實現(xiàn)xadmin后臺菜單改為中文

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

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

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

最新評論

阜宁县| 镇远县| 五大连池市| 霍州市| 开阳县| 寻甸| 马山县| 襄城县| 内丘县| 工布江达县| 东丰县| 神农架林区| 灌阳县| 丰镇市| 克什克腾旗| 湖州市| 富阳市| 济南市| 上林县| 平武县| 蒙自县| 大渡口区| 阜新| 铜川市| 文山县| 会理县| 万盛区| 沙洋县| 阳朔县| 石台县| 安新县| 天台县| 平邑县| 方城县| 巴东县| 同心县| 甘泉县| 塘沽区| 浪卡子县| 开平市| 兴义市|