Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

Administrator / pygame_lesson5_diy5

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Commit 7f22903f authored a year ago by BellCodeEditor's avatar BellCodeEditor
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

save project

parent f862ee32
Hide whitespace changes
Inline Side-by-side
Showing with 27 additions and 19 deletions
  • my_music.py
my_music.py
View file @ 7f22903f
...@@ -5,6 +5,7 @@ import os ...@@ -5,6 +5,7 @@ import os
pygame.init() # 初始化 pygame.init() # 初始化
# 创建窗口 # 创建窗口
screen = pygame.display.set_mode((640, 480)) screen = pygame.display.set_mode((640, 480))
FPS = pygame.time.Clock()
# 载入图片、资源 # 载入图片、资源
bg_img = pygame.image.load('background.png') # 背景图 bg_img = pygame.image.load('background.png') # 背景图
play_img = pygame.image.load('play.png') # 播放按钮 play_img = pygame.image.load('play.png') # 播放按钮
...@@ -17,6 +18,7 @@ music_list=[] ...@@ -17,6 +18,7 @@ music_list=[]
volume = 0.2 volume = 0.2
path="C:\\Users\\dell\\Desktop\\test" path="C:\\Users\\dell\\Desktop\\test"
filelist=os.listdir(path) filelist=os.listdir(path)
music_list = []
for i in filelist: for i in filelist:
if i[-4:] ==".mp3" or i[-4:]==".ogg" or i[-4:]==".wav": if i[-4:] ==".mp3" or i[-4:]==".ogg" or i[-4:]==".wav":
music_list.append(i) music_list.append(i)
...@@ -48,7 +50,7 @@ while True: ...@@ -48,7 +50,7 @@ while True:
if event.type == locals.MOUSEBUTTONDOWN: if event.type == locals.MOUSEBUTTONDOWN:
if event.button == 1: if event.button == 1:
x,y = event.pos x,y = event.pos
if x > 270 and x <370 and y > 350 and y < 450: if x > 270 and x < 370 and y > 350 and y < 450:
# 次数增加 # 次数增加
click += 1 click += 1
if click % 2 == 0: if click % 2 == 0:
...@@ -57,22 +59,26 @@ while True: ...@@ -57,22 +59,26 @@ while True:
else: else:
play_button = play_img play_button = play_img
pygame.mixer.music.pause() pygame.mixer.music.pause()
if x > 120 and x < 220 and y > 350 and y < 400: if x > 420 and x < 520 and y > 350 and y < 450:
num -= 1 pygame.mixer.music.stop()
if num < 0: play_bytton = stop_img
num=len(music_list) -1 if click % 2 == 0:
pygame.mixer.music.load(path+"\\"+music_list[num]) click += 2
pygame.mixer.music.play() else:
play_button=stop_img click += 1
click=0 if x > 120 and x < 220 and y > 350 and y < 450:
if x > 420 and x < 520 and y > 350 and y < 400: num -= 1
num += 1 if num < 0:
if num > len(music_list)-1: num = len(music_list) - 1
num=0 pygame.mixer.music.load(path+"\\"+music_list[num])
pygame.mixer.music.load(path+"\\"+music_list[num]) pygame.mixer.music.play()
pygame.mixer.music.play() play_button=stop_img
play_button=stop_img
click=0 if click % 2 == 0:
click += 2
else:
click += 1
if pygame.mixer.music.get_busy() == False: if pygame.mixer.music.get_busy() == False:
...@@ -81,10 +87,11 @@ while True: ...@@ -81,10 +87,11 @@ while True:
num=0 num=0
pygame.mixer.music.load(path+"\\"+music_list[num]) pygame.mixer.music.load(path+"\\"+music_list[num])
pygame.mixer.music.play() pygame.mixer.music.play()
new_logo = pygame.transform.rotate(logo_img, angle) new_logo = pygame.transform.rotate(logo_img, -angle)
newRect = new_logo.get_rect(center=(320, 200)) newRect = new_logo.get_rect(center=(320, 200))
pos = (newRect[0], newRect[1]) pos = (newRect[0], newRect[1])
angle += 1 if play_button == stop_img:
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)) # 暂停按钮
...@@ -93,3 +100,4 @@ while True: ...@@ -93,3 +100,4 @@ while True:
screen.blit(next_img, (420, 350)) # 下一曲 screen.blit(next_img, (420, 350)) # 下一曲
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60)
This diff is collapsed. Click to expand it.
  • Write
  • Preview
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