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()
# 我是初学者,如有错误,请多多指教
pygame音乐播放器
最新推荐文章于 2024-04-30 18:45:50 发布