forked from luyishisi/The_python_code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_world.py
More file actions
46 lines (36 loc) · 1.2 KB
/
hello_world.py
File metadata and controls
46 lines (36 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#coding:utf-8
'''
本测试样例将创建一个窗口,然后显示一张图片,
'''
#!/usr/bin/env python
background_image_filename = '1.1.jpg'
mouse_image_filename = '2.jpg'
#制定图像文件名称
import pygame
from pygame.locals import *
from sys import exit
#从sys中使用结束函数
pygame.init()
#初始化pygame、
screen = pygame.display.set_mode((1280,800),RESIZABLE,32)
#创建一个窗口,并且制定大小。
pygame.display.set_caption("hello, world! ly first game!")
#设置窗口标题
background = pygame.image.load(background_image_filename).convert()
mouse_cursor = pygame.image.load(mouse_image_filename).convert_alpha()
while True:
for event in pygame.event.get():
if event.type == QUIT:
exit()
#若接受到退出事件后退出程序
screen.blit(background,(0,0))
#画出背景图
x,y = pygame.mouse.get_pos()
#获取鼠标的坐标
x -= mouse_cursor.get_width()/2
#获取鼠标图像的宽高计算新的xy的值,目的是为了能居中
y -= mouse_cursor.get_height()/2
screen.blit(mouse_cursor,(x,y))
#在新的值画上x,y。以及鼠标的图案。
pygame.display.update()
#刷新一下画面