前言
520,并非情人所属, 我们可以表白万物,
不管什么时候, 这都是一个特别的日子,
今天,我要表白所有, 心里有我的人!
在这个充满幸福的日子里, 我要把最美好的祝福,
送给心里有我的每一个人;
祝愿大家:
一生平安,身体健康,
生活幸福,家庭美满!

不知不觉又是520了,先的一年有多少人表白成功,又有多少人表白失败,
有多少步入婚姻的殿堂,又有谁单身至今,不管如何,
今天在这里希望不想单身的人们找到属于自己的幸福~

那么接下来就让我们来看看怎么代码表白吧~
“无套路表白” 💌
效果展示

设置了只能选A选项,点不了B选项,哈哈哈哈(当然点击上面的叉叉还是会关掉)

代码展示
import pygame
import random
import sys
# 根据背景图大小,设置游戏屏幕大小
WIDTH, HEIGHT = 1024, 576
# 不全屏
screen = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32)
# 全屏
# screen = pygame.display.set_mode((WIDTH, HEIGHT), pygame.FULLSCREEN, 32)
pygame.display.set_caption('小姐姐,你的快递到了。')
# 添加文本信息
def title(text, screen, scale, color=(0, 0, 0)):
font = pygame.font.SysFont('SimHei', 27)
textRender = font.render(text, True, color)
# 初始化文本的坐标
screen.blit(textRender, (WIDTH / scale[0], HEIGHT / scale[1]))
# 按钮
def button(text, x, y, w, h, color, screen):
pygame.draw.rect(screen, color, (x, y, w, h))
font = pygame.font.SysFont('SimHei', 20)
textRender = font.render(text, True, (255, 255, 255))
textRect = textRender.get_rect()
textRect.center = ((x+w/2), (y+h/2))
screen.blit(textRender, textRect)
# 生成随机的位置坐标
def get_random_pos():
x, y = random.randint(10, 600), random.randint(20, 500)
return x, y
# 点击答应按钮后显示的页面
def show_like_interface(screen):
screen.fill((255, 255, 255))
background1 = pygame.image.load('2.png').convert()
screen.blit(background1, (0, 0))
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
def main():
pygame.init()
clock = pygame.time.Clock()
# 添加背景音乐
pygame.mixer.music.load('手写的从前-周杰伦.mp3')
pygame.mixer.music.play(-1, 20)
pygame.mixer.music.set_volume(0.5)
# 设置不同意按钮属性
unlike_pos_x = 130
unlike_pos_y = 375
unlike_pos_width = 450
unlike_pos_height = 55
unlike_color = (115, 76, 243)
# 设置同意按钮属性
like_pos_x = 130
like_pos_y = 280
like_pos_width = 450
like_pos_height = 55
like_color = (115, 76, 243)
running = True
while running:
# 填充窗口
screen.fill((255, 255, 255))
# 添加背景图
background = pygame.image.load('1.png').convert()
screen.blit(background, (0, 0))
# 获取鼠标坐标
pos = pygame.mouse.get_pos

最低0.47元/天 解锁文章
492





