Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson1_5
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
a9ae2066
authored
Oct 16, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
1b1d5e3e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
0 deletions
wssb.py
wwsb.py
wssb.py
View file @
a9ae2066
...
@@ -2,7 +2,18 @@ import pygame
...
@@ -2,7 +2,18 @@ import pygame
from
pygame
import
locals
from
pygame
import
locals
pygame
.
init
()
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
background
=
pygame
.
image
.
load
(
""
)
right
=
pygame
.
image
.
load
(
""
)
food
=
pygame
.
image
.
load
(
""
)
body
=
pygame
.
image
.
load
(
""
)
while
True
:
while
True
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
exit
()
exit
()
screen
.
blit
(,(
0
,
0
))
screen
.
blit
(,(
240
,
120
))
screen
.
blit
(,(
210
,
120
,))
screen
.
blit
(,(
180
,
120
))
screen
.
blit
(,(
180
,
90
))
screen
.
blit
(,(
360
,
300
))
pygame
.
display
.
update
()
\ No newline at end of file
wwsb.py
0 → 100644
View file @
a9ae2066
import
pygame
,
sys
from
pygame.locals
import
*
def
print_text
(
font
,
x
,
y
,
text
,
color
=
(
0
,
0
,
0
)):
"""打印字体函数"""
img_text
=
font
.
render
(
text
,
True
,
color
)
screen
.
blit
(
img_text
,
(
x
,
y
))
pygame
.
init
()
# 字体
font1
=
pygame
.
font
.
SysFont
(
"方正粗黑宋简体"
,
18
)
# 鼠标的移动位置
mouse_x
=
mouse_y
=
0
move_x
=
move_y
=
0
mouse_down
=
mouse_up
=
0
mouse_down_x
=
mouse_down_y
=
0
mouse_up_x
=
mouse_up_y
=
0
screen
=
pygame
.
display
.
set_mode
((
400
,
400
))
pygame
.
display
.
set_caption
(
"监听鼠标活动"
)
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
QUIT
:
pygame
.
quit
()
sys
.
exit
()
elif
event
.
type
==
MOUSEMOTION
:
mouse_x
,
mouse_y
=
event
.
pos
move_x
,
mouse_y
=
event
.
rel
elif
event
.
type
==
MOUSEBUTTONDOWN
:
mouse_down
=
event
.
button
mouse_down_x
,
mouse_down_y
=
event
.
pos
elif
event
.
type
==
MOUSEBUTTONUP
:
mouse_up
=
event
.
button
mouse_up_x
,
mouse_up_y
=
event
.
pos
screen
.
fill
((
255
,
255
,
255
))
print_text
(
font1
,
0
,
0
,
"鼠标事件"
)
print_text
(
font1
,
0
,
20
,
"鼠标的位置:"
+
str
(
mouse_x
)
+
","
+
str
(
mouse_y
))
print_text
(
font1
,
0
,
40
,
"鼠标的偏移:"
+
str
(
move_x
)
+
","
+
str
(
move_y
))
print_text
(
font1
,
0
,
60
,
"鼠标按下:"
+
str
(
mouse_down
)
+
"在"
+
str
(
mouse_down_x
)
+
","
+
str
(
mouse_down_y
))
print_text
(
font1
,
0
,
80
,
"鼠标松开:"
+
str
(
mouse_up
)
+
"在"
+
str
(
mouse_up_x
)
+
","
+
str
(
mouse_up_y
))
x
,
y
=
pygame
.
mouse
.
get_pos
()
print_text
(
font1
,
0
,
180
,
"鼠标位置:"
+
str
(
x
)
+
","
+
str
(
y
))
b1
,
b2
,
b3
=
pygame
.
mouse
.
get_pressed
()
print_text
(
font1
,
0
,
200
,
"按钮:"
+
str
(
b1
)
+
","
+
str
(
b2
)
+
","
+
str
(
b3
))
pygame
.
display
.
update
()
\ No newline at end of file
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