python抖音表白程序源代码


Posted in Python onApril 07, 2019

本文实例为大家分享了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()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python ljust rjust center输出
Sep 06 Python
python连接mysql并提交mysql事务示例
Mar 05 Python
python实现JAVA源代码从ANSI到UTF-8的批量转换方法
Aug 10 Python
python画出三角形外接圆和内切圆的方法
Jan 25 Python
Python学习之Django的管理界面代码示例
Feb 10 Python
详解Django之auth模块(用户认证)
Apr 17 Python
python爬虫之urllib,伪装,超时设置,异常处理的方法
Dec 19 Python
Python 如何提高元组的可读性
Aug 26 Python
pytorch实现onehot编码转为普通label标签
Jan 02 Python
使用PyTorch训练一个图像分类器实例
Jan 08 Python
keras 获取某层输出 获取复用层的多次输出实例
May 23 Python
python3中celery异步框架简单使用+守护进程方式启动
Jan 20 Python
我喜欢你 抖音表白程序python版
Apr 07 #Python
详解python爬虫系列之初识爬虫
Apr 06 #Python
为何人工智能(AI)首选Python?读完这篇文章你就知道了(推荐)
Apr 06 #Python
python基础梳理(一)(推荐)
Apr 06 #Python
详解python持久化文件读写
Apr 06 #Python
python七夕浪漫表白源码
Apr 05 #Python
python浪漫表白源码
Apr 05 #Python
You might like
php mssql 数据库分页SQL语句
2008/12/16 PHP
CakePHP框架Model关联对象用法分析
2017/08/04 PHP
PHP清除缓存的几种方法总结
2017/09/12 PHP
PHP安全之register_globals的on和off的区别
2020/07/23 PHP
JQuery扩展插件Validate 1 基本使用方法并打包下载
2011/09/05 Javascript
javascript动态添加、修改、删除对象的属性与方法详解
2014/01/27 Javascript
window.print打印指定div指定网页指定区域的方法
2014/08/04 Javascript
nodejs开发微博实例
2015/03/25 NodeJs
JavaScript生成二维码图片小结
2015/12/27 Javascript
JS实现的简单拖拽功能示例
2017/03/13 Javascript
详解plotly.js 绘图库入门使用教程
2018/02/23 Javascript
解决vue v-for src 图片路径问题 404
2019/11/12 Javascript
在vue中利用v-html按分号将文本换行的例子
2019/11/14 Javascript
Python for Informatics 第11章之正则表达式(四)
2016/04/21 Python
使用Python生成XML的方法实例
2017/03/21 Python
python 找出list中最大或者最小几个数的索引方法
2018/10/30 Python
python构造函数init实例方法解析
2020/01/19 Python
PyQt使用QPropertyAnimation开发简单动画
2020/04/02 Python
Django-migrate报错问题解决方案
2020/04/21 Python
django中related_name的用法说明
2020/05/20 Python
Django如何实现防止XSS攻击
2020/10/13 Python
python 还原梯度下降算法实现一维线性回归
2020/10/22 Python
详解基于python的图像Gabor变换及特征提取
2020/10/26 Python
团支书的期末学习总结自我评价
2013/11/01 职场文书
秋季运动会表扬稿
2014/01/16 职场文书
运动会100米解说词
2014/01/23 职场文书
机关党员2014全国两会学习心得体会
2014/03/10 职场文书
转让协议书范本
2014/09/13 职场文书
迁户口计划生育证明
2014/10/19 职场文书
留学推荐信(中英文版)
2015/03/26 职场文书
会议主持词开场白
2015/05/28 职场文书
民政局2016年“六一”儿童节慰问活动总结
2016/04/06 职场文书
《敬重卑微》读后感3篇
2019/11/26 职场文书
一次MySQL启动导致的事故实战记录
2021/09/15 MySQL
WINDOWS 64位 下安装配置mysql8.0.25最详细的教程
2022/03/22 MySQL
redis复制有可能碰到的问题汇总
2022/04/03 Redis