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
f00aab02
authored
Jan 22, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
5eb3b139
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
4 deletions
2.py
周二19.py
周五17点.py
2.py
0 → 100644
View file @
f00aab02
周二19.py
View file @
f00aab02
impor
t
pygame
impor
t
pygame
...
@@ -23,7 +23,7 @@ pygame.mixer.music.set_volume(volume)
...
@@ -23,7 +23,7 @@ pygame.mixer.music.set_volume(volume)
click
=
0
click
=
0
#创建一个变量play_button 记录播放和暂停的图片素材
#创建一个变量play_button 记录播放和暂停的图片素材
play_button
=
stop_img
play_button
=
stop_img
angle
=
0
path
=
r'C:\Users\左闭右开\Desktop\test\\'
path
=
r'C:\Users\左闭右开\Desktop\test\\'
#使用filelist来存放os打开的文件夹
#使用filelist来存放os打开的文件夹
filelist
=
os
.
listdir
(
path
)
filelist
=
os
.
listdir
(
path
)
...
@@ -31,6 +31,8 @@ filelist = os.listdir(path)
...
@@ -31,6 +31,8 @@ filelist = os.listdir(path)
for
i
in
filelist
:
for
i
in
filelist
:
if
i
[
-
4
:]
==
'.ogg'
or
i
[
-
4
:]
==
'.wav'
:
if
i
[
-
4
:]
==
'.ogg'
or
i
[
-
4
:]
==
'.wav'
:
list
.
append
(
i
)
list
.
append
(
i
)
font
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
12
)
while
True
:
while
True
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
#如果时间类型是本地的QUIT
#如果时间类型是本地的QUIT
...
@@ -66,7 +68,46 @@ while True:
...
@@ -66,7 +68,46 @@ while True:
else
:
else
:
pygame
.
mixer
.
music
.
pause
()
pygame
.
mixer
.
music
.
pause
()
play_button
=
play_img
play_button
=
play_img
if
x
>
120
and
x
<
220
and
y
>
350
and
y
<
400
:
pygame
.
mixer
.
music
.
load
(
path
+
list
[
num
])
pygame
.
mixer
.
music
.
play
()
num
-=
1
if
num
<
0
:
num
=
len
(
list
)
-
1
click
=
0
play_button
=
stop_img
music1
=
pygame
.
mixer
.
Sound
(
path
+
list
[
num
])
m_t
=
int
(
music1
.
get_length
())
if
x
>
420
and
x
<
520
and
y
>
350
and
y
<
400
:
pygame
.
mixer
.
music
.
load
(
path
+
list
[
num
])
pygame
.
mixer
.
music
.
play
()
num
+=
1
if
num
>
len
(
list
)
-
1
:
num
=
0
click
=
0
play_button
=
stop_img
music1
=
pygame
.
mixer
.
Sound
(
path
+
list
[
num
])
m_t
=
int
(
music1
.
get_length
())
#exit()
#exit()
new
=
pygame
.
transform
.
rotate
(
logo_img
,
angle
)
newRect
=
new
.
get_rect
(
center
=
(
320
,
200
))
pos
=
(
newRect
[
0
],
newRect
[
1
])
#变量pos存储不断变化的左上点的坐标
if
play_button
==
stop_img
:
angle
+=
1
#播放时长
time
=
pygame
.
mixer
.
music
.
get_pos
()
//
1000
#毫秒
#分钟
play_m
=
time
//
60
#秒
play_s
=
time
%
60
if
play_s
<
10
:
play_s
=
'0'
+
str
(
play_s
)
#文字内容
info
=
str
(
play_m
)
+
' : '
+
str
(
play_s
)
text
=
font
.
render
(
info
,
True
,(
255
,
255
,
255
))
#判断音乐的播放状态
#判断音乐的播放状态
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
#载入歌曲,通过列表名[索引]的方式去载入
#载入歌曲,通过列表名[索引]的方式去载入
...
@@ -78,12 +119,22 @@ while True:
...
@@ -78,12 +119,22 @@ while True:
#判断索引是否大于列表长度-1,大于就将列表索引设为0
#判断索引是否大于列表长度-1,大于就将列表索引设为0
if
num
>
len
(
list
)
-
1
:
if
num
>
len
(
list
)
-
1
:
num
=
0
num
=
0
music1
=
pygame
.
mixer
.
Sound
(
path
+
list
[
num
])
m_t
=
int
(
music1
.
get_length
())
print
(
m_t
)
music_m
=
m_t
//
60
music_s
=
m_t
%
60
if
music_s
<
10
:
music_s
=
'0'
+
str
(
music_s
)
info2
=
str
(
music_m
)
+
' : '
+
str
(
music_s
)
text2
=
font
.
render
(
info2
,
True
,(
255
,
255
,
255
))
# 绘制画面
# 绘制画面
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
screen
.
blit
(
play_button
,
(
270
,
330
))
# 暂停按钮
screen
.
blit
(
play_button
,
(
270
,
330
))
# 暂停按钮
screen
.
blit
(
logo_img
,
(
170
,
60
)
)
# 中间logo图
screen
.
blit
(
new
,
pos
)
# 中间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
))
# 下一曲
screen
.
blit
(
text
,(
120
,
450
))
screen
.
blit
(
text2
,(
160
,
450
))
# 刷新画面
# 刷新画面
pygame
.
display
.
update
()
pygame
.
display
.
update
()
周五17点.py
0 → 100644
View file @
f00aab02
import
pygame
import
pygame
from
pygame
import
locals
pygame
.
init
()
# 初始化
# 创建窗口
screen
=
pygame
.
display
.
set_mode
((
640
,
480
))
# 载入图片、资源
bg_img
=
pygame
.
image
.
load
(
'background.png'
)
# 背景图
play_img
=
pygame
.
image
.
load
(
'play.png'
)
# 播放按钮
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'
)
# 下一曲按钮
while
True
:
for
event
in
pygame
.
event
.
get
():
??
??
# 绘制画面
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
screen
.
blit
(
stop_img
,
(
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