Python—Bad Man Li Xingyun Small Project

import pygame
pygame.mixer.init()
screen=pygame.display.set_mode((1100,600))
pygame.display.set_caption("不良人")
p1=pygame.image.load("picture/li1.jpg")
p2=pygame.image.load("picture/li2.jpg")
rect1=p1.get_rect()
rect2=p2.get_rect()
limusic = pygame.mixer.Sound('Sound/liSound.MP3')
limusic.set_volume(20)
if pygame.mouse.get_focused():   #检查程序界面是否获得鼠标焦点
            curx, cury = pygame.mouse.get_pos()   #获取鼠标光标的位置
screen.blit(p2, (-88, -180))
while True:
    for event in pygame.event.get():
        if pygame.Rect.collidepoint(rect2, (curx, cury)) and event.type==pygame.MOUSEBUTTONDOWN:
            screen.blit(p1, (-80, 0))
            limusic.play()
            pygame.display.flip()
        if pygame.Rect.collidepoint(rect1, (curx, cury)) and event.type==pygame.MOUSEBUTTONUP:
            screen.blit(p2, (-150, -100))
            pygame.display.flip(),
        if event.type==pygame.QUIT:
            pygame.quit()
    pygame.display.flip()

After running the window, press the mouse button in the window to switch pictures and play a classic quote from Li Xingyun, release the mouse button to switch back to the previous picture!

screenshot:

Guess you like

Origin blog.csdn.net/H1727548/article/details/129658102