pygame 窗口标题和图标设置
窗口标题
pygame.display.set_caption(title, icontitle=None)
'''
• title设置窗口的标题内容
• icontitle设置图表化后的小标题
† 小标题可选,部分系统没有,一般不设置
'''
pygame.display.get_caption()
'''
• 返回当前设置窗口的标题及小标题内容
• 返回结构为(title, icontitle)
• 该函数与游戏交互逻辑配合,可以根据游戏情节修改标题内容
'''
设置图标
pygame.display.set_icon(surface)
'''
• 设置窗口的图标效果
• 图标是一个Surface对象
'''
游戏带图标
我把图标改成我的CSDN头像了格式:(128px*128px png格式)
导入图片设置成图标。
import pygame,sys
pygame.init()
icon = pygame.image.load("img/xyicon.png")
pygame.display.set_icon(icon) #设置图标
v = pygame.display.Info()
size = width,height = 600,400
speed = [1,1]
BLACK = 0, 0, 0
s = pygame.display.set_mode(size,pygame.RESIZABLE)
pygame.display.set_caption("hi 滑稽")
ball = pygame.image.load("img/361.png")
ballrect = ball.get_rect()
fps = 200
fclock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
speed[0] = speed[0] if speed[0] == 0 else (abs(speed[0]) - 1)*int(speed[0]/abs(speed[0]))
elif event.key == pygame.K_RIGHT:
speed[0] = speed[0] + 1 if speed[0] > 0 else speed[0] - 1
elif event.key == pygame.K_UP:
speed[1] = speed[1] + 1 if speed[1] > 0 else speed[1] - 1
elif event.key == pygame.K_DOWN:
speed[1] = speed[1] if speed[1] == 0 else (abs(speed[1]) - 1)*int(speed[1]/abs(speed[1]))
elif event.key == pygame.K_ESCAPE: # 获取ESC 按下时退出
sys.exit()
elif event.type == pygame.VIDEORESIZE:
size = width,height = event.w,event.h
s = pygame.display.set_mode(size,pygame.RESIZABLE)
ballrect = ballrect.move(speed)
if ballrect.left < 0 or ballrect.right > width:
speed[0] = - speed[0]
if ballrect.top < 0 or ballrect.bottom > height:
speed[1] = - speed[1]
pygame.display.get_caption()
s.fill(BLACK)
s.blit(ball, ballrect)
pygame.display.update()
fclock.tick(fps)