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 BeautifulSoup设置页面编码的方法
Apr 03 Python
Python CSV模块使用实例
Apr 09 Python
在Windows系统上搭建Nginx+Python+MySQL环境的教程
Dec 25 Python
机器学习之KNN算法原理及Python实现方法详解
Jul 09 Python
Django时区详解
Jul 24 Python
python GUI库图形界面开发之PyQt5信号与槽多窗口数据传递详细使用方法与实例
Mar 08 Python
Python IDLE或shell中切换路径的操作
Mar 09 Python
Python使用Chrome插件实现爬虫过程图解
Jun 09 Python
Django REST Framework 分页(Pagination)详解
Nov 30 Python
python获取天气接口给指定微信好友发天气预报
Dec 28 Python
python 模块重载的五种方法
Apr 24 Python
python实现剪贴板的操作
Jul 01 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实现的大文件切割与合并功能示例
2018/04/10 PHP
PHP实现搜索时记住状态的方法示例
2018/05/11 PHP
Nigma vs Liquid BO3 第二场2.14
2021/03/10 DOTA
用脚本调用样式的几种方法
2006/12/09 Javascript
javascript中bind函数的作用实例介绍
2014/09/28 Javascript
js模拟淘宝网的多级选择菜单实现方法
2015/08/18 Javascript
JavaScript对HTML DOM使用EventListener进行操作
2015/10/21 Javascript
JavaScript实现倒计时代码段Item1(非常实用)
2015/11/03 Javascript
认识Knockout及如何使用Knockout绑定上下文
2015/12/25 Javascript
AngularJS上拉加载问题解决方法
2016/05/23 Javascript
AngularJS实现的select二级联动下拉菜单功能示例
2017/10/25 Javascript
vue使用better-scroll实现下拉刷新、上拉加载
2018/11/23 Javascript
jquery分页优化操作实例分析
2019/08/23 jQuery
[51:14]LGD vs VP 2018国际邀请赛淘汰赛BO3 第一场 8.21
2018/08/22 DOTA
[39:21]LGD vs OG 2019国际邀请赛淘汰赛 胜者组 BO3 第二场 8.24
2019/09/10 DOTA
详解Python的Django框架中的模版继承
2015/07/16 Python
Python中特殊函数集锦
2015/07/27 Python
selenium+python实现自动化登录的方法
2018/09/04 Python
python判断数字是否是超级素数幂
2018/09/27 Python
解决pycharm的Python console不能调试当前程序的问题
2019/01/20 Python
Python3.5装饰器典型案例分析
2019/04/30 Python
使用tensorflow显示pb模型的所有网络结点方式
2020/01/23 Python
Python装饰器的应用场景代码总结
2020/04/10 Python
python如何查看安装了的模块
2020/06/23 Python
Python常用数字处理基本操作汇总
2020/09/10 Python
Visual Studio code 配置Python开发环境
2020/09/11 Python
您的健身减肥和健康饮食专家:vitafy
2017/06/06 全球购物
Java中有几种类型的流?JDK为每种类型的流提供了一些抽象类以供继承,请说出他们分别是哪些类?
2012/05/30 面试题
酒店总经理助理职责
2014/02/12 职场文书
公益广告语集锦
2014/03/13 职场文书
幼儿园六一儿童节主持节目串词
2014/03/21 职场文书
高中教师个人总结
2015/02/10 职场文书
吴仁宝观后感
2015/06/09 职场文书
汶川大地震感悟
2015/08/10 职场文书
用Python提取PDF表格的方法
2021/04/11 Python
vue组件冲突之引用另一个组件出现组件不显示的问题
2022/04/13 Vue.js