pygame库的学习

第一天:我学习了如何设置窗口和加载图片,以及加载音乐。这个库真的很有意思啊,打算py课设就拿这个写了。

代码:

import pygame

background_image_filename = 'taylor.jfif'
mouse_image_filename = 'mouse.jpg'
from pygame.locals import *
from sys import exit

pygame.init()
pygame.mixer.init()

screen = pygame.display.set_mode([1000, 600], 0, 32)
pygame.mixer.music.load('tay.mp3')
pygame.mixer.music.play()
pygame.display.set_caption("My dear taylor")
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 == pygame.QUIT:
            exit()
    screen.blit(background, (0, 0))

    x, y = pygame.mouse.get_pos()
    x -= mouse_cursor.get_width() // 2
    y -= mouse_cursor.get_height() // 2
    screen.blit(mouse_cursor, (x, y))
    pygame.display.update()
pygame.quit()

猜你喜欢

转载自www.cnblogs.com/SwiftAC/p/12164693.html
今日推荐