如何用 Python 撩抖音上的小姐姐?

2023-12-14 14:20
文章标签 python 小姐姐 撩抖 音上

本文主要是介绍如何用 Python 撩抖音上的小姐姐?,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

点击“开发者技术前线”,选择“星标🔝”

13:21 在看|星标|留言,  真爱

640?wx_fmt=jpeg

文章转载自公众号法纳斯特

都说抖音有毒,一刷就停不下来了,看来抖音这款产品紧紧抓住了人们内心深处的某些需求。

自古真情留不住,唯有套路得人心。这就给大家带来一个Python 的小套路。刷抖音的小伙伴,也许会有点印象。利用Python的pygame库,生成一个套路神器。


/ 01 / 无套路版本


无套路版本和抖音上的一些视频差不多。


就是点不了拒绝按钮...


详细代码如下。


 

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 + 5 and pos[0] > unlike_pos_x - 5 and pos[1] < unlike_pos_y + unlike_pos_height + 5 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 + 5 and pos[0] > unlike_pos_x - 5 and pos[1] < unlike_pos_y + unlike_pos_height + 5 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 + 5 and pos[0] > like_pos_x - 5 and pos[1] < like_pos_y + like_pos_height + 5 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()

运行代码,效果如下。



代码里是设置有音乐的,所以运行代码后,会有背景音乐。


这里因为小F的电脑太渣,录屏下的音质特别差。


所以选择录制一个无声的视频。


大家将就着看吧。


/ 02 / 套路版本


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


或许上面的那个版本只会让小姐姐觉得你很可恨...


毕竟强迫症患者有点多,愣是不让人点。


估摸着要挨小姐姐的揍。


所以便有了下面这个套路版本。


详细代码如下。


 

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 + 5 and pos[0] > unlike_pos_x - 5 and pos[1] < unlike_pos_y + unlike_pos_height + 5 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 + 5 and pos[0] > unlike_pos_x - 5 and pos[1] < unlike_pos_y + unlike_pos_height + 5 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 + 5 and pos[0] > unlike_pos_x - 5 and pos[1] < unlike_pos_y + unlike_pos_height + 5 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 + 5 and pos[0] > like_pos_x - 5 and pos[1] < like_pos_y + like_pos_height + 5 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()


运行代码,效果如下。



看出来那满满的套路了没。



/ 03 / 打包程序


看了上面一行行的代码,我们能直接交给女神吗?


答案不用想就知道的。


肯定是不能。


因为那样无疑是自取灭亡...


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


640?wx_fmt=png


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


640?wx_fmt=png

640?wx_fmt=png

640?wx_fmt=png

640?wx_fmt=png

640?wx_fmt=png

640?wx_fmt=png

640?wx_fmt=png

640?wx_fmt=png



/ 04 / 总结


小姐姐,你的快递到了。


什么快递? 


我的一厢情愿。


后台回复:“抖音小姐姐” 获取源码


电子书下载
640?wx_fmt=jpeg
👆关注公众号后台回复 :”深度学习“ 
深度学习详细的PDF电子版


这篇关于如何用 Python 撩抖音上的小姐姐?的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/492857

相关文章

Python的Darts库实现时间序列预测

《Python的Darts库实现时间序列预测》Darts一个集统计、机器学习与深度学习模型于一体的Python时间序列预测库,本文主要介绍了Python的Darts库实现时间序列预测,感兴趣的可以了解... 目录目录一、什么是 Darts?二、安装与基本配置安装 Darts导入基础模块三、时间序列数据结构与

Python正则表达式匹配和替换的操作指南

《Python正则表达式匹配和替换的操作指南》正则表达式是处理文本的强大工具,Python通过re模块提供了完整的正则表达式功能,本文将通过代码示例详细介绍Python中的正则匹配和替换操作,需要的朋... 目录基础语法导入re模块基本元字符常用匹配方法1. re.match() - 从字符串开头匹配2.

Python使用FastAPI实现大文件分片上传与断点续传功能

《Python使用FastAPI实现大文件分片上传与断点续传功能》大文件直传常遇到超时、网络抖动失败、失败后只能重传的问题,分片上传+断点续传可以把大文件拆成若干小块逐个上传,并在中断后从已完成分片继... 目录一、接口设计二、服务端实现(FastAPI)2.1 运行环境2.2 目录结构建议2.3 serv

通过Docker容器部署Python环境的全流程

《通过Docker容器部署Python环境的全流程》在现代化开发流程中,Docker因其轻量化、环境隔离和跨平台一致性的特性,已成为部署Python应用的标准工具,本文将详细演示如何通过Docker容... 目录引言一、docker与python的协同优势二、核心步骤详解三、进阶配置技巧四、生产环境最佳实践

Python一次性将指定版本所有包上传PyPI镜像解决方案

《Python一次性将指定版本所有包上传PyPI镜像解决方案》本文主要介绍了一个安全、完整、可离线部署的解决方案,用于一次性准备指定Python版本的所有包,然后导出到内网环境,感兴趣的小伙伴可以跟随... 目录为什么需要这个方案完整解决方案1. 项目目录结构2. 创建智能下载脚本3. 创建包清单生成脚本4

Python实现Excel批量样式修改器(附完整代码)

《Python实现Excel批量样式修改器(附完整代码)》这篇文章主要为大家详细介绍了如何使用Python实现一个Excel批量样式修改器,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一... 目录前言功能特性核心功能界面特性系统要求安装说明使用指南基本操作流程高级功能技术实现核心技术栈关键函

python获取指定名字的程序的文件路径的两种方法

《python获取指定名字的程序的文件路径的两种方法》本文主要介绍了python获取指定名字的程序的文件路径的两种方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 最近在做项目,需要用到给定一个程序名字就可以自动获取到这个程序在Windows系统下的绝对路径,以下

使用Python批量将.ncm格式的音频文件转换为.mp3格式的实战详解

《使用Python批量将.ncm格式的音频文件转换为.mp3格式的实战详解》本文详细介绍了如何使用Python通过ncmdump工具批量将.ncm音频转换为.mp3的步骤,包括安装、配置ffmpeg环... 目录1. 前言2. 安装 ncmdump3. 实现 .ncm 转 .mp34. 执行过程5. 执行结

Python实现批量CSV转Excel的高性能处理方案

《Python实现批量CSV转Excel的高性能处理方案》在日常办公中,我们经常需要将CSV格式的数据转换为Excel文件,本文将介绍一个基于Python的高性能解决方案,感兴趣的小伙伴可以跟随小编一... 目录一、场景需求二、技术方案三、核心代码四、批量处理方案五、性能优化六、使用示例完整代码七、小结一、

Python中 try / except / else / finally 异常处理方法详解

《Python中try/except/else/finally异常处理方法详解》:本文主要介绍Python中try/except/else/finally异常处理方法的相关资料,涵... 目录1. 基本结构2. 各部分的作用tryexceptelsefinally3. 执行流程总结4. 常见用法(1)多个e