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
b2548c51
authored
Jun 09, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
998e5b8d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
19 deletions
my_music.py
my_music.py
View file @
b2548c51
...
...
@@ -11,39 +11,41 @@ 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'
)
# 下一曲按钮
pygame
.
mixer
.
music
.
load
(
'歌曲4.ogg'
)
#导入音乐文件
volume
=
0.5
pygame
.
mixer
.
music
.
set_volume
(
volume
)
click
=
0
#统计次数
play_button
=
stop_img
pygame
.
mixer
.
music
.
load
(
'歌曲3.wav'
)
#导入音乐
volume
=
0.5
#控制音量大小的变量
pygame
.
mixer
.
music
.
set_volume
(
volume
)
#设置音量大小
click
=
0
#统计按下鼠标次数
button
=
stop_img
#按钮形状
while
True
:
for
event
in
pygame
.
event
.
get
():
#使用event遍历pygame中发生的事件
if
event
.
type
==
locals
.
QUIT
:
#如果事件是退出事件
exit
()
#那么就退出程序
#按下按键事件
if
event
.
type
==
locals
.
KEYDOWN
:
pygame
.
mixer
.
music
.
set_volume
(
volume
)
#设置音量大小
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
exit
()
#退出程序
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_UP
:
volume
+=
0.1
if
volume
>
1
:
if
volume
>
1
:
volume
=
1
if
event
.
key
==
locals
.
K_DOWN
:
if
event
.
key
==
locals
.
K_DOWN
:
volume
-=
0.1
if
volume
<
=
0
:
if
volume
<
0
:
volume
=
0
if
event
.
type
==
locals
.
MOUSEBUTTONDOWN
:
if
event
.
type
==
locals
.
MOUSEBUTTONDOWN
:
click
+=
1
if
click
%
2
==
0
:
play_
button
=
stop_img
button
=
stop_img
pygame
.
mixer
.
music
.
unpause
()
else
:
play_
button
=
play_img
button
=
play_img
pygame
.
mixer
.
music
.
pause
()
pygame
.
mixer
.
music
.
set_volume
(
volume
)
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
#判断音乐是否播放
pygame
.
mixer
.
music
.
play
()
#播放音乐
# 绘制画面
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
screen
.
blit
(
play_
button
,
(
270
,
330
))
# 暂停按钮
screen
.
blit
(
button
,
(
270
,
330
))
# 暂停按钮
screen
.
blit
(
logo_img
,
(
170
,
60
))
# 中间logo图
screen
.
blit
(
last_img
,
(
120
,
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