pygame库的学习

二次信任 提交于 2020-01-08 08:37:51

第一天:我学习了如何设置窗口和加载图片,以及加载音乐。这个库真的很有意思啊,打算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()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!