python 制作簡單的音樂播放器
更新時間:2020年11月25日 16:30:10 作者:kalebujordan
這篇文章主要介紹了python 制作簡單的音樂播放器,幫助大家更好的理解和學習python,感興趣的朋友可以了解下
如你所見,功能很簡單。只有基本的播放,停止,甚至只針對一首歌曲,僅供初學者參考學習用。
代碼
from tkinter import * from tkinter import filedialog from pygame import mixer class MusicPlayer: def __init__(self, window ): window.geometry('320x100'); window.title('Iris Player'); window.resizable(0,0) Load = Button(window, text = 'Load', width = 10, font = ('Times', 10), command = self.load) Play = Button(window, text = 'Play', width = 10,font = ('Times', 10), command = self.play) Pause = Button(window,text = 'Pause', width = 10, font = ('Times', 10), command = self.pause) Stop = Button(window ,text = 'Stop', width = 10, font = ('Times', 10), command = self.stop) Load.place(x=0,y=20);Play.place(x=110,y=20);Pause.place(x=220,y=20);Stop.place(x=110,y=60) self.music_file = False self.playing_state = False def load(self): self.music_file = filedialog.askopenfilename() def play(self): if self.music_file: mixer.init() mixer.music.load(self.music_file) mixer.music.play() def pause(self): if not self.playing_state: mixer.music.pause() self.playing_state=True else: mixer.music.unpause() self.playing_state = False def stop(self): mixer.music.stop() root = Tk() app= MusicPlayer(root) root.mainloop()
以上就是python 制作簡單的音樂播放器的詳細內(nèi)容,更多關(guān)于python 音樂播放器的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Python讀取大量Excel文件并跨文件批量計算平均值的方法
這篇文章主要介紹了Python讀取大量Excel文件并跨文件批量計算平均值,介紹基于Python語言,實現(xiàn)對多個不同Excel文件進行數(shù)據(jù)讀取與平均值計算的方法,需要的朋友可以參考下2023-02-02解決pytorch load huge dataset(大數(shù)據(jù)加載)
這篇文章主要介紹了解決pytorch load huge dataset(大數(shù)據(jù)加載)的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-05-05使用pycharm連接讀取orcl數(shù)據(jù)庫的表的操作方法
這篇文章主要介紹了使用pycharm連接讀取orcl數(shù)據(jù)庫的表的操作方法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧2024-01-01