关于python 的一些小项目(四)

音乐播放器

#!/user/bin/env python

# -*-coding: utf-8 -*-

import pygame

import os

from tkinter import *

root = Tk()

root.title('狗子专用播放器')

root.geometry('800x600')

pygame.init()

music_path = r'E:\Administrator'

current_play = '阿涵 - 过客.mp3'

music_name = StringVar()

def play():

    music_name.set(current_play)

    pygame.mixer.music.load(os.path.join(music_path, current_play))

    pygame.mixer.music.play()

Label(root, textvariable=music_name, font=('宋体', 14), justify='center',bg='#ADD8E6').place(relx=0,rely=0.1,relwidth=1,relheight=0.3)

Button(root, text="播放", command=play).place(relx=0,rely=0.5,relwidth=0.2,relheight=0.1)

Button(root, text="暂停", command=lambda: pygame.mixer.music.pause()).place(relx=0.2,rely=0.5,relwidth=0.2,relheight=0.1)

Button(root, text="恢复", command=lambda: pygame.mixer.music.unpause()).place(relx=0.4,rely=0.5,relwidth=0.2,relheight=0.1)

Button(root, text="停止", command=lambda: pygame.mixer.music.stop()).place(relx=0.6,rely=0.5,relwidth=0.2,relheight=0.1)

Button(root, text="重播", command=lambda: pygame.mixer.music.rewind()).place(relx=0.8,rely=0.5,relwidth=0.2,relheight=0.1)

root.mainloop()

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,468评论 0 23
  • #### Pygame: Pygame是被设计用来写游戏的python模块集合,Pygame是在优秀的SDL库之上...
    夜旧语阅读 6,283评论 0 1
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,159评论 0 10
  • 傅镜殊变了。方灯以为他明白世俗,但是内心仍有善良,没有变成彻头彻底的没有心的人。可是傅明殊的所作所为都是方灯失望,...
    墨绿瓶阅读 3,633评论 0 0