赞
踩
- import pygame
- import tkinter as tk
- import threading
- from tkinter.filedialog import askopenfilename
-
- '''
- Pygame是一组功能强大而有趣的模块,可用于管理图形、动画乃至声音,可以让我们很轻松的开发复杂的游戏。
- 通过使用Pygame来处理在屏幕上绘制图像等任务,不用考虑众多繁琐而艰难的编码的工作,而是将重点放在程序的高级逻辑上。
- 小试牛刀
- 安装库
- pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pygame
- '''
- def music():
- #global file_path, Image
- file_path = ''
- file_path = askopenfilename(title='请打开要操作的文件',
- filetypes=[('音乐', '*.mp3 *.ogg '), ('所有文件', '*')],
- initialdir='.\\')
- pygame.mixer.music.load(file_path)
- pygame.mixer.music.play(-1,0.0)
-
- def play():
- try:
- t = threading.Thread(target=music())
- t.setDaemon(True)
- t.start()
- except:
- pass
-
- def stop():
- try:
- pygame.mixer.music.stop()
- except:
- pass
-
- def quit():
- exit()
-
- if __name__ == '__main__':
-
- pygame.init() #
- window = tk.Tk()
- window.title('音乐播放\' 1.0') # 窗口标题
- window.geometry('400x300') # 这里的乘是小x
-
- bn_play = tk.Button(window, text='播放', font=('Arial', 12), width=10, height=1, command=play)
- bn_play.place(x=80, y=40)
- bn_stop = tk.Button(window, text='停止', font=('Arial', 12), width=10, height=1, command=stop)
- bn_stop.place(x=200, y=40)
- bn_quit = tk.Button(window, text='关闭', font=('Arial', 12), width=10, height=1, command=quit)
- bn_quit.place(x=80, y=100)
- window.mainloop()
-
-
-
-
-
-

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。