Commit e2b2c0c3 by BellCodeEditor

save project

parent c0ab8cfa
last.png

3.79 KB

logo.png

40.9 KB

import pygame
import os
from pygame import locals
pygame.init() # 初始化
# 创建窗口
screen = pygame.display.set_mode((640, 480))
# 载入图片、资源
bg= pygame.image.load('background.png') # 背景图
play= pygame.image.load('play.png') # 播放按钮
stop= pygame.image.load('stop.png') # 暂停按钮
last= pygame.image.load('last.png') # 上一曲按钮
next= pygame.image.load('next.png') # 下一曲按钮
logo= pygame.image.load('logo.png') # 中间logo
music_list=[]
num=-1
path='C:\\Users\\86187\\Desktop\\test'
filelist= os.listdir(path)
for i in filelist:
if i[-4:]==".mp3":
music_list.append(i)
volume=0.2
pygame.mixer.music.set_volume(volume)
click=0
play_button=stop
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
exit()
if event.type ==locals.KEYDOWN:
if event.key == locals.K_UP and volume<1:
volume += 0.1
if event.key == locals.K_DOWN and volume>0:
volume -= 0.1
pygame.mixer.music.set_volume(volume)
if event.type ==locals.MOUSEBUTTONDOWN:
if event.button==1:
x,y=event.pos
if x>270 and x<370 and y>350 and y<450:
click += 1
if click % 2 == 0:
play_button = stop
pygame.mixer.music.unpause()
if click % 2 == 1:
play_button = play
pygame.mixer.music.pause()
if pygame.mixer.music.get_busy()==False:
num=num+1
if num>len(music_list)-1:
num=0
pygame.mixer.music.load(path+'\\'+music_list[num])
pygame.mixer.music.play()
# 绘制画面
screen.blit(bg, (0, 0)) # 填充背景
screen.blit(play_button, (270, 330)) # 暂停按钮
screen.blit(logo, (170, 60)) # 中间logo图
screen.blit(last, (120, 350)) # 上一曲
screen.blit(next, (420, 350)) # 下一曲
# 刷新画面
pygame.display.update()
\ No newline at end of file
File added
next.png

3.87 KB

play.png

12.1 KB

stop.png

11.6 KB

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment