Commit 26004523 by BellCodeEditor

auto save

parent 2f19bc03
Showing with 7 additions and 31 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import os
pygame.init() # 初始化 pygame.init() # 初始化
# 创建窗口 # 创建窗口
...@@ -12,15 +11,11 @@ stop_img = pygame.image.load('stop.png') # 暂停按钮 ...@@ -12,15 +11,11 @@ stop_img = pygame.image.load('stop.png') # 暂停按钮
last_img = pygame.image.load('last.png') # 上一曲按钮 last_img = pygame.image.load('last.png') # 上一曲按钮
next_img = pygame.image.load('next.png') # 下一曲按钮 next_img = pygame.image.load('next.png') # 下一曲按钮
logo_img = pygame.image.load('logo.png') # 下一曲按钮 logo_img = pygame.image.load('logo.png') # 下一曲按钮
music_list = [] music_list = ['歌曲1.wav','歌曲2.wav','歌曲3.wav','歌曲4.ogg']
path = 'C:\\Users\\Administrator\\Desktop\\text'
filelist = os.listdir(path)
for file in filelist:
if file[-4:] == '.wav' or file[-4:] == '.ogg':
music_list.append(file)
volume = 0.2 volume = 0.2
pygame.mixer.music.set_volume(volume) # 初始播放音量 pygame.mixer.music.set_volume(volume) # 初始播放音量
click = 0 click = 0
angle = 1
play_button = stop_img play_button = stop_img
nem = -1 nem = -1
while True: while True:
...@@ -54,36 +49,16 @@ while True: ...@@ -54,36 +49,16 @@ while True:
else: else:
play_button = play_img play_button = play_img
pygame.mixer.music.pause() pygame.mixer.music.pause()
if event.type == locals.MOUSEBUTTONDOWN:
if event.button == 1:
x,y = event.pos
if x > 120 and x < 220 and y > 350 and y < 400:
nem -= 1
if nem < 0:
nem = len(music_list)-1
pygame.mixer.music.load(path+"\\"+music_list[nem])
pygame.mixer.music.play()
click = 0
play_button = stop_img
if event.type == locals.MOUSEBUTTONDOWN:
if event.button == 1:
x,y = event.pos
if x > 420 and x < 520 and y > 350 and y < 400:
nem += 1
if nem > 3:
nem = 0
pygame.mixer.music.load(path+"\\"+music_list[nem])
pygame.mixer.music.play()
click = 0
play_button = stop_img
if pygame.mixer.music.get_busy() == False: if pygame.mixer.music.get_busy() == False:
nem += 1 nem += 1
# 载入音乐 # 载入音乐
pygame.mixer.music.load(path+"\\"+music_list[nem]) pygame.mixer.music.load(music_list[nem])
if nem >len(music_list)-1: if nem >len(music_list)-1:
nem = 0 nem = 0
pygame.mixer.music.play() pygame.mixer.music.play()
new_img=pygame.transform.rotate(stop_img,angle)
angle += 1
# 绘制画面 # 绘制画面
screen.blit(bg_img, (0, 0)) # 填充背景 screen.blit(bg_img, (0, 0)) # 填充背景
screen.blit(play_button, (270, 330)) # 暂停按钮 screen.blit(play_button, (270, 330)) # 暂停按钮
...@@ -92,3 +67,4 @@ while True: ...@@ -92,3 +67,4 @@ while True:
screen.blit(next_img, (420, 350)) # 下一曲 screen.blit(next_img, (420, 350)) # 下一曲
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
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