python仿抖音表白神器
作者:weixin_33704234 发布时间:2023-03-15 03:35:56
标签:python,抖音,表白
Python能够干嘛?
可以做日常任务,比如自动备份你的MP3;
可以做网站,很多著名的网站像知乎、YouTube就是Python写的;
可以做网络游戏的后台,很多在线游戏的后台都是Python开发的。
上面说的这些本人并没有实现过;
但是我知道Python可以做一些有趣的东西,比如仿制抖音表白小软件;
本人也是刚刚学习Python,这个脚本通过百度找到的,然后自己也重新写了一遍,加深了映像,最主要的还是思路要清晰;
流程:
1、创建一个游戏屏幕
2、加载title
3、加载button,
4、当鼠标移动到 '算了吧' 上面的时候 重加加载桌面并随机生成一个 '算了吧' 坐标;
5、当鼠标移动到 ‘好呀'上面时 显示不同的title
以下就是Python脚本:
import pygame
import random
# 设置游戏屏幕大小 这是一个常量
WIDTH, HEIGHT = 640, 480
screen = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32)
pygame.display.set_caption('FROM一个喜欢你很久的小哥哥')
# 标题
def title(text, screen, scale, color=(255, 0, 0)):
font = pygame.font.SysFont('SimHei', WIDTH//(len(text)*2))
textRender = font.render(text, True, color)
# 获取此图片的矩形框
# textRect = textRender.get_rect()
# textRect.midtop = (WIDTH/scale[0], HEIGHT/scale[1])
# screen.blit(textRender, textRect)
# 初始化文字的坐标
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, (0, 0, 0))
textRect = textRender.get_rect()
textRect.center = ((x+w/2), (y+h/2))
screen.blit(textRender, textRect)
# 生成随机的位置坐标
def get_random_pos():
x, y = random.randint(20, 620), random.randint(20, 460)
return x, y
# 点击喜欢按钮后显示的页面
def show_like_interface(text, screen, color=(255, 0, 0)):
screen.fill((255, 255, 255))
font = pygame.font.SysFont('SimHei', WIDTH//(len(text)))
textRender = font.render(text, True, color)
textRect = textRender.get_rect()
textRect.midtop = (WIDTH/2, HEIGHT/2)
screen.blit(textRender, textRect)
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
def main():
pygame.init()
clock = pygame.time.Clock()
unlike_pos_x = 330
unlike_pos_y = 250
unlike_pos_width = 80
unlike_pos_height = 40
unlike_color = (0, 191, 255)
like_pos_x = 180
like_pos_y = 250
like_pos_width = 80
like_pos_height = 40
like_color = (0, 191, 255)
running = True
while running:
# 填充窗口
screen.fill((255, 255, 255))
img = pygame.image.load('d:/love2.png')
imgRect = img.get_rect()
imgRect.midtop = int(WIDTH / 1.3), HEIGHT // 7
screen.blit(img, imgRect)
# 获取坐标
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('小姐姐,我观察你很久了', screen, scale=[5, 8])
title('做我女朋友好不好呀', screen, scale=[5, 4])
button('好呀', like_pos_x, like_pos_y, like_pos_width, like_pos_height, like_color, screen)
button('算了吧', 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:
pygame.quit()
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:
show_like_interface('我就知道小姐姐你也喜欢我~', screen, color=(255, 0, 0))
pygame.display.flip()
pygame.display.update()
clock.tick(60)
main()
大家有好的创意也可以一起交流下;
来源:https://blog.csdn.net/weixin_33704234/article/details/86837635


猜你喜欢
- 我就废话不多说了,大家还是直接看代码吧~n = input("1st enter:")print(n)print(typ
- 暴力的重启服务方案一般服务器重启可以直接通过 kill 命令杀死进程,然后重新启动一个新的进程即可。但这种方法比较粗暴,有可能导致某些正在处
- 代码如下:Dim strName, iLoop For Each strName 
- 删除一条留言信息会级联删除回复信息,这时我们需要用到事务,如下SQLALTER PROCEDURE [dbo].[proc_tb_leave
- 前言任何应用都离不开数据,所以在学习python的时候,当然也要学习一个如何用python操作数据库了。MySQLdb就是python对my
- 本文主要给大家介绍的是关于Golang解析json数据的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍:使用 Gol
- 2008北京奥运会块到了,下面的js代码将告诉你,离奥运会开幕还要多少天!让我们一起迎接这美好的时刻。相关文章推荐:各种北京2008奥运会倒
- 什么是触发器?触发器是在对表进行插入、更新或删除操作时自动执行的存储过程。 触发器对表进行插入、更新、删除的时候会自动执行的特殊存储过程。触
- 代码import osfrom PIL import Imageimport tkinterimport tkinter.filedialo
- python中的Reportlab模块reportlab模块是用python语言生成pdf文件的模块安装:pip install repor
- 一、循环语句介绍 1.循环语句理解循环语句允许我们执行一个语句或语句组多次,可以让我们的代码重复的去执行。2.循环语句示意图二、循
- 这里列出了13种实现图片或网页内容 lightbox 效果的方法,大部分是链接到各种lightbox作者的英文页面,里面都有源代码下载。Th
- 最近在做压力测试嘛,需要逐步增加用户量做验证,每个用户单独创建数据库进行连接,就要不断去创建数据库,这个报错也很容易理解,mysql连接数不
- 本节内容深浅拷贝循环方式字典常用方法总结一、深浅拷贝列表、元组、字典(以及其他)对于列表、元组和字典而言,进行赋值(=)、浅拷贝(copy)
- 二维数组二维数组本质上是以数组作为数组元素的数组,即“数组的数组”,类型说明符 数组名[常量表达式][常量表达式]。二维数组又称为矩阵,行列
- 最近开始学Python,想直接通过命令行的方式进行学习。奈何没有Tab补全,操作实在麻烦,网上各种百度后无果(x64系统,x86的可以直接下
- Python的3.0版本,常被称为Python 3000,或简称Py3k。相对于Python的早期版本,这是一个较大的升级。为了不带入过多的
- 实现思路需求需要将本数据库的数据进行处理(添加前缀),然后导入主数据库。但是当前数据库记录的create_time、update_time
- 在调试爬虫的时候,新手都会遇到关于ip的错误,好好的程序突然报错了,怎么解决,关于ip访问的错误其实很好解决,但是怎么知道解决好了呢?怎么确
- 首先来看,ASP读取ACCESS数据库。代码如下:<% @language="VBScript"&nbs