Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson5_diy1
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
a4e19e80
authored
Nov 05, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
416791a9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
5 deletions
my_music.py
my_music.py
View file @
a4e19e80
import
pygame
import
pygame
from
pygame
import
locals
from
pygame
import
locals
import
os
pygame
.
init
()
# 初始化
pygame
.
init
()
# 初始化
pygame
.
mixer
.
init
()
pygame
.
mixer
.
init
()
...
@@ -13,8 +14,15 @@ last_img = pygame.image.load('last.png') # 上一曲按钮
...
@@ -13,8 +14,15 @@ 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
(
"test.wav"
)
music_list
=
[]
path
=
r"C:\Users\科技馆\Desktop\src"
for
ele
in
os
.
listdir
(
path
):
if
ele
[
-
4
:]
==
'.wav'
or
ele
[
-
4
:]
==
'.ogg'
:
music_list
.
append
(
ele
)
print
(
music_list
)
index
=
0
volume
=
0.2
volume
=
0.2
play_status
=
True
play_status
=
True
button
=
stop_img
button
=
stop_img
...
@@ -35,10 +43,18 @@ while True:
...
@@ -35,10 +43,18 @@ while True:
if
volume
<
0
:
if
volume
<
0
:
volume
=
0
volume
=
0
# 按下鼠标
# 按下鼠标
if
event
.
type
==
locals
.
MOUSEBUTTONDOWN
:
if
event
.
type
==
locals
.
MOUSEBUTTONDOWN
:
play_status
=
not
play_status
if
event
.
button
==
1
:
x
,
y
=
event
.
pos
if
x
>
270
and
x
<
370
and
y
>
330
and
y
<
430
:
play_status
=
not
play_status
if
x
>
120
and
x
<
220
and
y
>
350
and
y
<
400
:
index
-=
2
pygame
.
mixer
.
music
.
stop
()
if
x
>
420
and
x
<
520
and
y
>
350
and
y
<
400
:
index
+=
0
pygame
.
mixer
.
music
.
stop
()
if
play_status
==
True
:
if
play_status
==
True
:
button
=
stop_img
button
=
stop_img
pygame
.
mixer
.
music
.
unpause
()
pygame
.
mixer
.
music
.
unpause
()
...
@@ -47,9 +63,10 @@ while True:
...
@@ -47,9 +63,10 @@ while True:
pygame
.
mixer
.
music
.
pause
()
pygame
.
mixer
.
music
.
pause
()
pygame
.
mixer
.
music
.
set_volume
(
volume
)
pygame
.
mixer
.
music
.
set_volume
(
volume
)
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
pygame
.
mixer
.
music
.
load
(
path
+
'
\\
'
+
music_list
[
index
%
len
(
music_list
)])
pygame
.
mixer
.
music
.
play
()
pygame
.
mixer
.
music
.
play
()
play_status
=
True
# 绘制画面
index
+=
1
# 绘制画面
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
screen
.
blit
(
button
,
(
270
,
330
))
# 暂停按钮
screen
.
blit
(
button
,
(
270
,
330
))
# 暂停按钮
screen
.
blit
(
logo_img
,
(
170
,
60
))
# 中间logo图
screen
.
blit
(
logo_img
,
(
170
,
60
))
# 中间logo图
...
...
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