Commit bcf444b4 by BellCodeEditor

auto save

parent 19f22638
Showing with 94 additions and 11 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import os
pygame.init() # 初始化 pygame.init() # 初始化
# 创建窗口 # 创建窗口
...@@ -10,18 +11,34 @@ play_img = pygame.image.load('play.png') # 播放按钮 ...@@ -10,18 +11,34 @@ play_img = pygame.image.load('play.png') # 播放按钮
stop_img = pygame.image.load('stop.png') # 暂停按钮 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') # 中间按钮
# 载入音乐 # 载入音乐
pygame.mixer.music.load('歌曲4.ogg') # 载入音乐
volume = 0.2 volume = 0.2
pygame.mixer.music.set_volume(volume) # 初始播放音量 pygame.mixer.music.set_volume(volume) # 初始播放音量
click = 0 click = 0
play_button = stop_img play_button = stop_img
#定义一个音乐列表
music_list=[]
#定义索引变量
num=-1
#定义路径变量
path="C:\\Users\\赵志\\Desktop\\音乐播放器"
filelist=os.listdir(path)#listdir(路径)获取指定路径下所有的文档,并且以列表的形式返回
for i in filelist:
if i[-4:]==".wav" or i[-4:]==".ogg":
music_list.append(i)
#定义角度变量
angle=0
#创建字体
my_font=pygame.font.Font("neuropol.ttf",18)
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
# print(event)
if event.type == locals.QUIT: if event.type == locals.QUIT:
exit() exit()
# 按键,控制声音大小 # 按键,控制声音大小
...@@ -38,22 +55,66 @@ while True: ...@@ -38,22 +55,66 @@ while True:
pygame.mixer.music.set_volume(volume) pygame.mixer.music.set_volume(volume)
if event.type == locals.MOUSEBUTTONDOWN: if event.type == locals.MOUSEBUTTONDOWN:
click += 1 if event.button==1:
if click % 2 == 0: x,y=event.pos
play_button = stop_img if x>270 and x<370 and y>330 and y<430:
pygame.mixer.music.unpause() click += 1
else: if click % 2 == 0:
play_button = play_img play_button = stop_img
pygame.mixer.music.pause() pygame.mixer.music.unpause()
else:
play_button = play_img
pygame.mixer.music.pause()
#上一曲
if x>120 and x<220 and y>350 and y<400:
num -= 1
if num<0:
num=len(music_list)-1
pygame.mixer.music.load(path+"\\"+music_list[num]) # 载入音乐
pygame.mixer.music.play()#播放
click=0
play_button = stop_img
#下一曲
if x>420 and x<520 and y>350 and y<400:
num += 1
if num>len(music_list)-1:
num=0
pygame.mixer.music.load(path+"\\"+music_list[num]) # 载入音乐
pygame.mixer.music.play()#播放
click=0
play_button = stop_img
if pygame.mixer.music.get_busy() == False: if pygame.mixer.music.get_busy() == False:
num += 1
if num>len(music_list)-1:#len()列表长度
num=0
pygame.mixer.music.load(path+"\\"+music_list[num]) # 载入音乐
pygame.mixer.music.play() pygame.mixer.music.play()
"""
transform--转换模块--rotate(图片,角度)--返回旋转之后的图片
"""
#唱盘旋转
new_logo=pygame.transform.rotate(logo_img,angle)
rect=new_logo.get_rect(center=(320,200))#get_rect()获取到新图形的矩形的数据,以元组的形式返回(x坐标,y坐标,宽度,高度)
# print(rect)
pos=(rect[0],rect[1])
if play_button==stop_img:
angle +=1
#当前歌曲播放的进度
play_time=pygame.mixer.music.get_pos()#get_pos()获取到当前播放音乐所对应的时间,以毫秒返回
play_time=int(play_time/1000)
play_m=play_time//60#分钟
play_s=play_time%60#秒数
info=str(play_m)+":"+str(play_s)
text=my_font.render(info,True,(255,255,255))
# 绘制画面 # 绘制画面
screen.blit(bg_img, (0, 0)) # 填充背景 screen.blit(bg_img, (0, 0)) # 填充背景
screen.blit(play_button, (270, 330)) # 暂停按钮 screen.blit(play_button, (270, 330)) # 暂停按钮
screen.blit(logo_img, (170, 60)) # 中间logo图 screen.blit(new_logo, pos) # 中间logo图
screen.blit(last_img, (120, 350)) # 上一曲 screen.blit(last_img, (120, 350)) # 上一曲
screen.blit(next_img, (420, 350)) # 下一曲 screen.blit(next_img, (420, 350)) # 下一曲
screen.blit(text,(120,440))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
\ No newline at end of file
"""
元组()---不可变的
列表[]---可变
"""
# tuple1=(100,200,300)
# x,y,z=tuple1#变量连续赋值
# print(x)
# print(y)
# print(z)
# import os
# path="C:\\Users\\赵志\\Desktop\\音乐播放器"
# filelist=os.listdir(path)#listdir(路径)获取指定路径下所有的文档,并且以列表的形式返回
# print(filelist)
print(8/3)
print(8//3)#整除---》就近于比当前小数小的整数
print(-1//2)
\ 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