pygame音乐播放器

import pygame
import time
from pygame.locals import *
from sys import exit
import os
from tkinter import filedialog
'''
f = open("music_play_file_set","r")
list = f.read()
f.close()
list = eval(list)
print(list)
bg = list["bg"]
print(bg)
title = list["title"]
'''
filepath = "觉醒年代.mp3"
def main():
    global filepath,bg
    background_image_file = "sea.jpg"
    pygame.init()
    pygame.display.set_caption("title")
    screen = pygame.display.set_mode((1000, 700), 0, 32)
    background = pygame.image.load(background_image_file).convert()
    bg_x, bg_y = 0, 0
    bg_move_x, bg_move_y = 0, 0

    zt = pygame.image.load("暂停.bmp")
    jxbf = pygame.image.load("继续.bmp")
    yybf = pygame.image.load("音乐播放.bmp")
    xzwj = pygame.image.load("选择文件.bmp")
    yl = pygame.image.load("alien1.png")
    settings = pygame.image.load("设置.bmp")

    mouse_file = "mouse.png"
    mouse = pygame.image.load(mouse_file)
    a = 200
    b = 600
    while True:
        time.sleep(0.01)
        mykeyslist = pygame.key.get_pressed()

        mouse_x, mouse_y = pygame.mouse.get_pos()

        pygame.mouse.set_visible(False)

        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                exit()

            if event.type == pygame.MOUSEBUTTONDOWN:
                if (mouse_x <= 300 and mouse_x >= 100 and mouse_y >= 100 and mouse_y <= 200):
                    pygame.mixer.music.pause()
                elif (mouse_x <= 700 and mouse_x >= 500 and mouse_y >= 100 and mouse_y <= 200):
                    pygame.init()
                    pygame.mixer.init()
                    pygame.mixer.music.load(filepath)
                    pygame.mixer.music.set_volume(1.0)
                    pygame.mixer.music.play()
                elif (300 >= mouse_x >= 100 and mouse_y >= 300 and mouse_y <= 400):
                    pygame.mixer.music.unpause()
                elif (mouse_x <= 700 and mouse_x >= 500 and mouse_y >= 300 and mouse_y <= 400):
                    filepath = filedialog.askopenfilename()
                elif (mouse_x <= 40 and mouse_x >= 0 and mouse_y >= 0 and mouse_y <= 40):
                    print("hello,world")
                    os.popen()

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    pygame.mixer.music.pause()
                if event.key == pygame.K_b:
                    pygame.mixer.music.unpause()
                if event.key == pygame.K_ESCAPE:
                    pygame.quit()
                    exit()
                if event.key == pygame.K_a:
                    pygame.init()
                    pygame.mixer.init()
                    pygame.mixer.music.load(filepath)
                    pygame.mixer.music.set_volume(1.0)
                    pygame.mixer.music.play()
        if mykeyslist[pygame.K_RIGHT]:
            a = a + 1
        if mykeyslist[pygame.K_LEFT]:
            a = a - 1
        if mykeyslist[pygame.K_UP]:
            b = b - 1
        if mykeyslist[pygame.K_DOWN]:
            b = b + 1
        pygame.mixer.music.set_volume(a / 1000)
        screen.fill((0, 0, 0))
        screen.blit(background, (bg_x, bg_y))
        screen.blit(zt, (100, 100))
        screen.blit(jxbf, (100, 300))
        screen.blit(xzwj, (500, 300))
        screen.blit(settings, (1, 1))
        screen.blit(yybf, (500, 100))
        screen.blit(yl, (a, b))
        screen.blit(mouse, (mouse_x, mouse_y))

        pygame.display.update()
if __name__ == '__main__':
    main()

# 我是初学者,如有错误,请多多指教

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值