Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson04_diy
This project
Loading...
Sign in
Toggle navigation
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
e1faa705
authored
Jun 09, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
094b04de
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
1 deletions
my_music.py
my_music.py
View file @
e1faa705
...
@@ -13,16 +13,41 @@ next_img = pygame.image.load('next.png') # 下一曲按钮
...
@@ -13,16 +13,41 @@ next_img = pygame.image.load('next.png') # 下一曲按钮
logo_img
=
pygame
.
image
.
load
(
'logo.png'
)
# 中间logo
logo_img
=
pygame
.
image
.
load
(
'logo.png'
)
# 中间logo
pygame
.
mixer
.
music
.
load
(
'歌曲1.wav'
)
# 载入音乐
pygame
.
mixer
.
music
.
load
(
'歌曲1.wav'
)
# 载入音乐
volume
=
0.8
# 新建变量volume初始值设为0.8
pygame
.
mixer
.
music
.
set_volume
(
volume
)
# 初始播放音量
click
=
0
# 新建变量click初始值设为0
play_button
=
stop_img
# 创建变量play_button表示播放按钮造型并初始值设为stop_img暂停造型
while
True
:
while
True
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
# if判断事件类型编号与locals模块的QUIT事件编号是否相等
if
event
.
type
==
locals
.
QUIT
:
# if判断事件类型编号与locals模块的QUIT事件编号是否相等
exit
()
# 接收到退出事件后退出程序
exit
()
# 接收到退出事件后退出程序
# 按键,控制声音大小
if
event
.
type
==
locals
.
KEYDOWN
:
# if判断键盘是否按下
if
event
.
key
==
locals
.
K_w
:
# if判断w键是否按下
volume
+=
0.1
# 音量增加0.1
if
volume
>
1
:
# if判断音量大于1
volume
=
1
# 音量设为1
pygame
.
mixer
.
music
.
set_volume
(
volume
)
# 初始播放音量
if
event
.
key
==
locals
.
K_s
:
# if判断s键是否按下
volume
-=
0.1
# 音量减少0.1
if
volume
<
0
:
# if判断音量少于0
volume
=
0
# 音量设为0
pygame
.
mixer
.
music
.
set_volume
(
volume
)
# 初始播放音量
if
event
.
type
==
locals
.
MOUSEBUTTONDOWN
:
click
+=
1
if
click
%
2
==
0
:
play_button
=
stop_img
pygame
.
mixer
.
music
.
unpause
()
else
:
play_button
=
play_img
pygame
.
mixer
.
music
.
pause
()
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
# if判断音乐是否正在播放
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
# if判断音乐是否正在播放
pygame
.
mixer
.
music
.
play
()
# 播放音乐
pygame
.
mixer
.
music
.
play
()
# 播放音乐
# 绘制画面
# 绘制画面
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
screen
.
blit
(
stop_img
,
(
270
,
330
))
# 暂停按钮
screen
.
blit
(
play_button
,
(
270
,
330
))
# 暂停按钮
screen
.
blit
(
logo_img
,
(
170
,
60
))
# 中间logo图
screen
.
blit
(
logo_img
,
(
170
,
60
))
# 中间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
))
# 下一曲
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment