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

Administrator / pygame_lesson5_diy2

  • 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 14152275 authored 3 years ago by BellCodeEditor's avatar BellCodeEditor
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

save project

parent fcdcb706
Hide whitespace changes
Inline Side-by-side
Showing with 43 additions and 10 deletions
  • .py
  • my_music.py
.py 0 → 100644
View file @ 14152275
import os
a=os.listdir(r'C:\Users\Administrator\Desktop\新建文件夹')
for i in a:
print(i)
120 220 350 450
\ No newline at end of file
This diff is collapsed. Click to expand it.
my_music.py
View file @ 14152275
import pygame
from pygame import locals
import os
from os import listdir
pygame.init() # 初始化
# 创建窗口
ml=[]
num= -1
path='C:\\Users\\Administrator\\Desktop\\新建文件夹'
mlist=listdir(path)
for i in mlist:
if i[-4:] == '.wav' or i[-4:] == '.ogg':
ml.append(i)
screen = pygame.display.set_mode((640, 480))
# 载入图片、资源
bg_img = pygame.image.load('background.png') # 背景图
......@@ -12,9 +20,9 @@ stop_img = pygame.image.load('stop.png') # 暂停按钮
last_img = pygame.image.load('last.png') # 上一曲按钮
next_img = pygame.image.load('next.png') # 下一曲按钮
logo_img = pygame.image.load('logo.png') # 下一曲按钮
#ml=['歌曲1.wav','歌曲2.wav','歌曲3.wav','歌曲4.ogg']
# 载入音乐
pygame.mixer.music.load('歌曲4.ogg') # 载入音乐
# 载入音乐
volume = 0.2
pygame.mixer.music.set_volume(volume) # 初始播放音量
......@@ -27,12 +35,12 @@ while True:
exit()
# 按键,控制声音大小
if event.type == locals.KEYDOWN:
if event.key == locals.K_UP:
if event.key == locals.K_w or event.key == locals.K_UP:
volume += 0.1
if volume > 1:
volume = 1
pygame.mixer.music.set_volume(volume)
if event.key == locals.K_DOWN:
if event.key == locals.K_s or event.key == locals.K_DOWN:
volume -= 0.1
if volume < 0:
volume = 0
......@@ -42,16 +50,35 @@ while True:
if event.type == locals.MOUSEBUTTONDOWN:
if event.button==1:
x,y=event.pos
if x>120 and x<220 and y>350 and y<450:
num-=1
click=0
if num<0:
num=len(ml)-1
pygame.mixer.music.load('C:\\Users\\Administrator\\Desktop\\新建文件夹'+'\\'+ml[num])
pygame.mixer.music.play()
if x>420 and x<520 and y>350 and y<450:
num+=1
click=0
if num>len(ml)-1:
num=0
pygame.mixer.music.load('C:\\Users\\Administrator\\Desktop\\新建文件夹'+'\\'+ml[num])
pygame.mixer.music.play()
if x>270 and x<370 and y>350 and y<450:
click += 1
if click % 2 == 0:
play_button = stop_img
pygame.mixer.music.unpause()
else:
play_button = play_img
pygame.mixer.music.pause()
if click % 2 == 0:
play_button = stop_img
pygame.mixer.music.unpause()
else:
play_button = play_img
pygame.mixer.music.pause()
#120 220 350 450
if pygame.mixer.music.get_busy() == False:
num+=1
if num>len(ml)-1:
num=0
pygame.mixer.music.load('C:\\Users\\Administrator\\Desktop\\新建文件夹'+'\\'+ml[num])
pygame.mixer.music.play()
# 绘制画面
......
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