01 pygame
import pygame
# 1.初始化
pygame.init()
# 2.创建 游戏窗口
screen = pygame.display.set_mode((600, 400))
# 游戏循环
while True:
for event in pygame.event.get():
#检测窗口上的关闭按钮是否被点击
if event.type == pygame.QUIT:
#退出游戏
print('关闭按钮')
exit()
02 显示文字
import pygame
if __name__ == "__main__":
pygame.init()
screen = pygame.display.set_mode((600,400))
#设置窗口的背景颜色
screen.fill((255,255,255))
# 1.创建系统文字
"""
创建自定义字体
Font(字体文件路径,字体大小)
"""
font = pygame.font.Font("./font/aa.ttf",50)
#font = pygame.font.SysFont("Times",50)
# 2.根据字体创建数据对象
"""
color --> 计算机三原色(红 ,绿 蓝 ) RGB颜色范围0--255
"""
surface = font.render("你好",True,(0,255,0))
# 3.将内容添加到窗口上
"""
bilt (需要显示的对象,显示坐标)
需要显示的对象
"""
screen.blit(surface,(100,100))
# 4.将窗口内容展示出来
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
03 显示图片
import pygame
if __name__ == "__main__":
pygame.init()
screen = pygame.display.set_mode((600,1000))
screen.fill((255,255,255))
# 1.获取图片路径
image = pygame.image.load("./font/111.jpg")
# a.获取图片大小
image_size = image.get_size()
print(image_size)
# b.图片 缩放 旋转和平移
image = pygame.transform.scale(image,(600,400))
# c.旋转 (对象,角度)
image= pygame.transform.rotate(image,90)
# d.rotozoom(旋转对象.钻转角度,旋转比例)
# 2.将图片对象渲染在窗口上
screen.blit(image,(0,0))
# 3.展示在屏幕上
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
04 显示图形
pygame
if __name__ == "__main__":
pygame.init()
screen = pygame.display.set_mode((600,400))
screen.fill((255,255,255))
"""
line (
Surface --> 画在哪个地方
color -->线的颜色
star_pos
end_pos
width
"""
pygame.draw.line(screen,(255,0,0),(78,59),(200,300),5)
pygame.draw.line(screen, (255, 0, 0), (78, 59), (200, 500), 5)
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
网友评论