Commit 2f68b5c2 by BellCodeEditor

save project

parent 1754f9f4
Showing with 23 additions and 2 deletions
import pygame
from pygame import locals
import os
pygame.init() # 初始化
# 创建窗口
......@@ -14,19 +15,26 @@ logo_img = pygame.image.load('logo.png') # 下一曲按钮
# 载入音乐
pygame.mixer.music.load('歌曲4.ogg') # 载入音乐
music=[]
path='C:\\Users\\EDZ\\Desktop\\test'
filelist=os.listdir(path)
for i in filelist:
if i[-4:]=='.wav'or i[-4:]=='.ogg':
music.append(i)
volume = 0.2
pygame.mixer.music.set_volume(volume) # 初始播放音量
click = 0
play_button = stop_img
num=-1
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:
volume += 0.1
if volume > 1:
volume = 1
......@@ -39,6 +47,9 @@ while True:
# 按下鼠标
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:
......@@ -49,8 +60,13 @@ while True:
pygame.mixer.music.pause()
if pygame.mixer.music.get_busy() == False:
num+=1
if num>len(music)-1:
num = 0
pygame.mixer.music.load(path+'\\'+music[num])
pygame.mixer.music.play()
# 绘制画面
screen.blit(bg_img, (0, 0)) # 填充背景
screen.blit(play_button, (270, 330)) # 暂停按钮
......
import os
path=("C:\\Users\\EDZ\\Desktop\\test")
filelist=os.listdir(path)
print(filelist)
\ No newline at end of file
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