Python 表白?别傻了,女神是拿来撩的!

百家 作者:程序人生 2019-02-14 05:14:05

作者 | 小F

责编 | 伍杏玲


自古真情留不住,唯有套路得人心。

今天是情人节,程序员如何撩动心仪女神的心?当然要用程序员的方法了!

这马上给大家带来一个Python的小套路:利用Python的pygame库,生成一个套路神器。


无套路版本


无套路版本和抖音上的一些视频差不多,就是点不了拒绝按钮!是不是很实用捏?

详细代码如下:

import pygame
import random
import sys

# 根据背景图大小,设置游戏屏幕大小
WIDTH, HEIGHT = 1024576
# 不全屏
screen = pygame.display.set_mode((WIDTH, HEIGHT), 032)
# 全屏
# screen = pygame.display.set_mode((WIDTH, HEIGHT), pygame.FULLSCREEN, 32)
pygame.display.set_caption('小姐姐,你的快递到了。')


# 添加文本信息
def title(text, screen, scale, color=(000)):
    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, (255255255))
        textRect = textRender.get_rect()
        textRect.center = ((x+w/2), (y+h/2))
        screen.blit(textRender, textRect)


# 生成随机的位置坐标
def get_random_pos():
        x, y = random.randint(10600), random.randint(20500)
        return x, y


# 点击答应按钮后显示的页面
def show_like_interface(screen):
    screen.fill((255255255))
    background1 = pygame.image.load('214_1.jpg').convert()
    screen.blit(background1, (00))
    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('214_1.mp3')
    pygame.mixer.music.play(-120)
    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 = (11576243)
    # 设置同意按钮属性
    like_pos_x = 130
    like_pos_y = 280
    like_pos_width = 450
    like_pos_height = 55
    like_color = (11576243)

    running = True
    while running:
        # 填充窗口
        screen.fill((255255255))
        # 添加背景图
        background = pygame.image.load('214_2.jpg').convert()
        screen.blit(background, (00))

        # 获取鼠标坐标
        pos = pygame.mouse.get_pos()
        # 判断鼠标位置,不同意时,按钮不断变化
        if pos[0] <  unlike_pos_x + unlike_pos_width + and pos[0] > unlike_pos_x - 5 and pos[1] <  unlike_pos_y + unlike_pos_height + and pos[1] > unlike_pos_y - 5:
            while True:
                unlike_pos_x, unlike_pos_y = get_random_pos()
                if pos[0] <  unlike_pos_x + unlike_pos_width + and pos[0] > unlike_pos_x - 5 and pos[1] <  unlike_pos_y + unlike_pos_height + and pos[1] > unlike_pos_y - 5:
                    continue
                break

        # 设置标题及按钮文本信息
        title('1.如果有一天我向你表白,你会怎么样?', screen, scale=[83])
        button('A.你小子终于开窍了,你敢表白我就敢答应!', like_pos_x, like_pos_y, like_pos_width, like_pos_height, like_color, screen)
        button('B.我拿你当闺蜜,你居然想睡我!果断拒绝!', unlike_pos_x, unlike_pos_y, unlike_pos_width, unlike_pos_height, unlike_color, screen)
        # 设置关闭选项属性
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
        # 当鼠标点击同意按钮后,跳转结束页面
        if pos[0] <  like_pos_x + like_pos_width + and pos[0] > like_pos_x - 5 and pos[1] <  like_pos_y + like_pos_height + and pos[1] > like_pos_y - 5:
            if event.type == pygame.MOUSEBUTTONDOWN:
                show_like_interface(screen)

        pygame.display.flip()
        pygame.display.update()
        clock.tick(60)


main()

运行代码,效果如下。

<iframe class="video_iframe" data-vidtype="1" data-cover="http%3A%2F%2Fshp.qpic.cn%2Fqqvideo_ori%2F0%2Fp0837frdg51_496_280%2F0" allowfullscreen="" frameborder="0" data-ratio="1.6954732510288066" data-w="824" data-src="http://v.qq.com/iframe/player.html?vid=p0837frdg51&width=352&height=198&auto=0" width="352" height="198" data-vh="198" data-vw="352" style="display: none; width: 352px !important; height: 198px !important;"></iframe>

代码里是设置有音乐的,所以运行代码后,会有背景音乐。这里因为我的电脑太渣,录屏下的音质特别差,所以选择录制一个无声的视频,大家将就着看吧。


套路版本


或许上面的那个版本只会让小姐姐觉得你很可恨,毕竟强迫症患者有点多,愣是不让人点,估摸着要挨小姐姐的揍。所以便有了下面这个套路版本,详细代码如下:

import pygame
import random
import sys

# 根据背景图大小,设置游戏屏幕大小
WIDTH, HEIGHT = 1024576
screen = pygame.display.set_mode((WIDTH, HEIGHT), 032)
pygame.display.set_caption('小姐姐,你的快递到了。')


# 添加文本信息
def title(text, screen, scale, color=(000)):
    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, color_text):
        pygame.draw.rect(screen, color, (x, y, w, h))
        font = pygame.font.SysFont('SimHei'20)
        textRender = font.render(text, True, color_text)
        textRect = textRender.get_rect()
        textRect.center = ((x+w/2), (y+h/2))
        screen.blit(textRender, textRect)


# 生成随机的位置坐标
def get_random_pos():
        x, y = random.randint(20620), random.randint(20460)
        return x, y


# 点击答应后显示的页面
def show_like_interface(screen):
    screen.fill((255255255))
    background1 = pygame.image.load('214_1.jpg').convert()
    screen.blit(background1, (00))
    pygame.display.update()
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()


# 点击不答应按钮后显示的页面
def show_unlike_interface(screen):
    screen.fill((255255255))
    background_1 = pygame.image.load('214_3.jpg').convert()
    screen.blit(background_1, (00))
    pygame.display.update()
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()


def main():
    num = 0
    pygame.init()
    clock = pygame.time.Clock()
    # 添加背景音乐
    pygame.mixer.music.load('214_2.mp3')
    pygame.mixer.music.play(-140)
    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 = (11576243)
    # 设置同意按钮属性
    like_pos_x = 130
    like_pos_y = 280
    like_pos_width = 450
    like_pos_height = 55
    like_color = (11576243)

    running = True
    while running:
        # 填充窗口
        screen.fill((255255255))
        # 添加背景图
        background = pygame.image.load('214_2.jpg').convert()
        screen.blit(background, (00))

        # 获取鼠标坐标
        pos = pygame.mouse.get_pos()
        if pos[0] <  unlike_pos_x + unlike_pos_width + and pos[0] > unlike_pos_x - 5 and pos[1] <  unlike_pos_y + unlike_pos_height + and pos[1] > unlike_pos_y - 5:
            while True:
                if num > 5:
                    break
                num += 1
                unlike_pos_x, unlike_pos_y = get_random_pos()
                if pos[0] <  unlike_pos_x + unlike_pos_width + and pos[0] > unlike_pos_x - 5 and pos[1] <  unlike_pos_y + unlike_pos_height + and pos[1] > unlike_pos_y - 5:
                    continue
                break

        # 设置标题及按钮文本信息
        title('1.如果有一天我向你表白,你会怎么样?', screen, scale=[83])
        button('A.你小子终于开窍了,你敢表白我就敢答应!', like_pos_x, like_pos_y, like_pos_width, like_pos_height, like_color, screen, (255255255))
        # 设置小套路文本
        if num <  6:
            button('B.我拿你当闺蜜,你居然想睡我!果断拒绝!', unlike_pos_x, unlike_pos_y, unlike_pos_width, unlike_pos_height, unlike_color, screen, (255255255))
        if num > 5:
            button('B. 我拿你当闺蜜,你居然想睡我!果断答应!', unlike_pos_x, unlike_pos_y, unlike_pos_width, unlike_pos_height, unlike_color, screen, (255255255))
        # 设置套路文本
        if num == 1:
            button('操作提示:请直接点击答案,切勿手抖!', unlike_pos_x, unlike_pos_y - 50, unlike_pos_width, unlike_pos_height, (255255255), screen, (19200))
        if num == 2:
            button('咋又抖了?女神是不是哪里不舒服?', unlike_pos_x, unlike_pos_y - 50, unlike_pos_width, unlike_pos_height, (255255255), screen, (19200))
        if num == 3:
            button('呀!看来这病得还不轻啊!', unlike_pos_x, unlike_pos_y - 50, unlike_pos_width, unlike_pos_height, (255255255), screen, (19200))
        if num == 4:
            button('生了病也没人照料,心疼……', unlike_pos_x, unlike_pos_y - 50, unlike_pos_width, unlike_pos_height, (255255255), screen, (19200))
        if num == 5:
            button('好险!差点儿就点到了呢!', unlike_pos_x, unlike_pos_y - 50, unlike_pos_width, unlike_pos_height, (255255255), screen, (19200))
        if num == 6:
            button('哎,算了,不躲了,你选吧', unlike_pos_x, unlike_pos_y - 50, unlike_pos_width, unlike_pos_height, (255255255), screen, (19200))

        # 点击套路按钮
        if num > 5:
            if pos[0] <  unlike_pos_x + unlike_pos_width + and pos[0] > unlike_pos_x - 5 and pos[1] <  unlike_pos_y + unlike_pos_height + and pos[1] > unlike_pos_y - 5:
                if event.type == pygame.MOUSEBUTTONDOWN:
                    show_unlike_interface(screen)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
        # 点击同意按钮
        if pos[0] <  like_pos_x + like_pos_width + and pos[0] > like_pos_x - 5 and pos[1] <  like_pos_y + like_pos_height + and pos[1] > like_pos_y - 5:
            if event.type == pygame.MOUSEBUTTONDOWN:
                show_like_interface(screen)

        pygame.display.flip()
        pygame.display.update()
        clock.tick(60)


main()

效果如下:

<iframe class="video_iframe" data-vidtype="1" data-cover="http%3A%2F%2Fshp.qpic.cn%2Fqqvideo_ori%2F0%2Fu0837locfx6_496_280%2F0" allowfullscreen="" frameborder="0" data-ratio="1.6954732510288066" data-w="824" data-src="http://v.qq.com/iframe/player.html?vid=u0837locfx6&width=352&height=198&auto=0" width="352" height="198" data-vh="198" data-vw="352" style="display: none; width: 352px !important; height: 198px !important;"></iframe>


打包程序


看了上面一行行的代码,我们能直接交给女神吗?那样无疑是自取灭亡。

所以使用pyinstaller库将代码、图片及音乐素材打包成exe文件。

直接点击love.exe程序,即可运行。

源码地址:https://pan.baidu.com/s/1zAAX8FuNht9r01LRnC_ZpA

本文系作者投稿,版权归作者所有。

# 欢迎来评论区留言 #

你打算情人节送什么礼物呢?

 热 文 推 荐 

年后跳槽:哪些迹象告诉我们,公司可能不行了?

35 岁程序员,年后第一天被辞退

“不厚道”的程序员:年后第一天上班就提辞职

DevOps“兵器”60样,你都会使哪几样?

假期倒计时, 这份完整区块链开发资源列表, 赶紧收藏学起来!

承认《流浪地球》就那么难吗?

深度学习的黑暗时代已来临?

她说:是的,嫁人当嫁程序员!

print_r('点个好看吧!');
var_dump('点个好看吧!');
NSLog(@"点个好看吧!");
System.out.println("点个好看吧!");
console.log("点个好看吧!");
print("点个好看吧!");
printf("点个好看吧!");
cout < < "点个好看吧!" < < endl;
Console.WriteLine("点个好看吧!");
fmt.Println("点个好看吧!");
Response.Write("点个好看吧!");
alert("点个好看吧!")
echo "点个好看吧!"


喜欢就点击“好看”吧

关注公众号:拾黑(shiheibook)了解更多

[广告]赞助链接:

四季很好,只要有你,文娱排行榜:https://www.yaopaiming.com/
让资讯触达的更精准有趣:https://www.0xu.cn/

公众号 关注网络尖刀微信公众号
随时掌握互联网精彩
赞助链接