python抖音表白程序源代码
作者:black_hole6 发布时间:2021-01-29 17:12:38
标签:python,抖音,表白
本文实例为大家分享了python抖音表白程序的具体代码,供大家参考,具体内容如下
import sys
import random
import pygame
from pygame.locals import *
WIDTH, HEIGHT = 640, 480
BACKGROUND = (0, 191, 255)
# 按钮
def button(text, x, y, w, h, color, screen):
pygame.draw.rect(screen, color, (x, y, w, h))
font = pygame.font.Font('./font/simkai.ttf', 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 title(text, screen, scale, color=(255, 0, 0)):
font = pygame.font.Font('./font/simkai.ttf', 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)
# 生成随机的位置坐标
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(BACKGROUND)
font = pygame.font.Font('./font/simkai.ttf', 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 == QUIT:
pygame.quit()
sys.exit()
# 主函数
def main():
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32)
pygame.display.set_caption('FROM一个喜欢你很久的小哥哥')
clock = pygame.time.Clock()
pygame.mixer.music.load('./bg_music/1.mp3')
pygame.mixer.music.play(-1, 30.0)
pygame.mixer.music.set_volume(0.25)
unlike_pos_x = 330
unlike_pos_y = 300
unlike_pos_width = 100
unlike_pos_height = 50
like_pos_x = 180
like_pos_y = 300
like_pos_width = 100
like_pos_height = 50
running = True
like_color = (255, 0, 255)
while running:
screen.fill(BACKGROUND)
img = pygame.image.load("./imgs/1.png")
imgRect = img.get_rect()
imgRect.midtop = WIDTH//2, HEIGHT//4
screen.blit(img, imgRect)
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_pos = pygame.mouse.get_pos()
if mouse_pos[0] < like_pos_x+like_pos_width+5 and mouse_pos[0] > like_pos_x-5 and\
mouse_pos[1] < like_pos_y+like_pos_height+5 and mouse_pos[1] > like_pos_y-5:
like_color = BACKGROUND
running = False
mouse_pos = pygame.mouse.get_pos()
if mouse_pos[0] < unlike_pos_x+unlike_pos_width+5 and mouse_pos[0] > unlike_pos_x-5 and\
mouse_pos[1] < unlike_pos_y+unlike_pos_height+5 and mouse_pos[1] > unlike_pos_y-5:
while True:
unlike_pos_x, unlike_pos_y = get_random_pos()
if mouse_pos[0] < unlike_pos_x+unlike_pos_width+5 and mouse_pos[0] > unlike_pos_x-5 and\
mouse_pos[1] < unlike_pos_y+unlike_pos_height+5 and mouse_pos[1] > unlike_pos_y-5:
continue
break
title('小姐姐,我观察你很久了', screen, scale=[2, 10])
title('做我女朋友好不好呀', screen, scale=[2, 6])
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, (255, 0, 255), screen)
pygame.display.flip()
pygame.display.update()
clock.tick(60)
show_like_interface('我就知道小姐姐你也喜欢我~', screen, color=(255, 0, 0))
if __name__ == '__main__':
main()
来源:https://blog.csdn.net/lbperfect123/article/details/82928123
0
投稿
猜你喜欢
- 这里给大家分享一段使用PHP Socket 编程模拟Http post和get请求的代码,非常的实用,结尾部分我们再讨论下php模拟http
- 先让我们看一个例子,了解什么是模式化窗口。以下是QQ秀商城在非登录时提示登录的一种状态。当我在非登录状态,通过保存形象的方式买一件衣服时,弹
- 相信没有人不知道 Firebug 是什么东西,但有时候我们糟糕的代码不想让同行轻松的使用 F12 就能一览无遗。那么怎么办呢?这里有个猥琐的
- Python最近挺火呀,比鹿晗薛之谦还要火,当然是在程序员之间。下面我们看看有关Python的相关内容。上一篇文章我们已经介绍了部分Pyth
- 京东商品详细的请求处理,是先显示html,然后再ajax请求处理显示价格。1.可以运行js,并解析之后得到的html2.模拟js请求,得到价
- uWSGI是一个Web应用服务器,它具有应用服务器,代理,进程管理及应用监控等功能。它支持WSGI协议,同时它也支持自有的uWSGI协议,该
- splinter介绍 Splinter是一个使用Python测试Web应用程序的开源工具,可以自动化浏览器操作,例如访问URL和与它们的项
- 前几天,杨超越编程大赛火了,大家都在报名参加,而我也是其中的一员。在我们的项目中,我负责的是数据爬取这块,我主要是把对于杨超越 的
- 本文实例为大家分享了Python实现简单扫雷游戏的具体代码,供大家参考,具体内容如下#coding: utf-8__note__ = &qu
- 代码如下: <!--[if IE 6]><script type="text/javascript"&
- 简介python 动态执行字符串代码片段(也可以是文件), 一般会用到exec,eval。execexec_stmt ::= "e
- 本文实例分析了python对json的相关操作。分享给大家供大家参考,具体如下:什么是json:JSON(JavaScript Object
- 这里的Counter是指collections中的Counter,通过Counter可以实现字典的创建以及字典key出现频次的统计。然而,使
- 这个是我在蓝色看到的,楼主想实现图片按比例缩放的功能(缩略图),把图片固定在一定的宽高范围内,不会变形,失真。例如:缩略图的框是94px*9
- 最近要做个从 pdf 文件中抽取文本内容的工具,大概查了一下 python 里可以使用 pdfminer 来实现。下面就看看怎样使用吧。PD
- 本文实例讲述了php tpl模板引擎定义与使用。分享给大家供大家参考,具体如下:tpl.php<?phpnamespace tpl;/
- 人们很容易忽视图像img标签的alt属性。然而,它的重要性也无法体现出来,它是有利于网页的accessibility and&nb
- 用程序来求积分的方法有很多,这篇文章主要是有关牛顿-科特斯公式。学过插值算法的同学最容易想到的就是用插值函数代替被积分函数来求积分,但实际上
- 本文实例讲述了Python socket实现的简单通信功能。分享给大家供大家参考,具体如下:套接字(socket)是计算机网络数据结构,在任
- 使用命令行时,如果要添加选项的话,python 2.3里新增加了一个模块叫optparse,也是专门来处理命令行选项的。from optpa