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实现猜数字游戏(无重复数字)示例分享
Mar 29 Python
独特的python循环语句
Nov 20 Python
一张图带我们入门Python基础教程
Feb 05 Python
Python脚本实现自动将数据库备份到 Dropbox
Feb 06 Python
python机器学习之决策树分类详解
Dec 20 Python
快速排序的四种python实现(推荐)
Apr 03 Python
用python解压分析jar包实例
Jan 16 Python
python正则过滤字母、中文、数字及特殊字符方法详解
Feb 11 Python
Python 实现自动完成A4标签排版打印功能
Apr 09 Python
python plt可视化——打印特殊符号和制作图例代码
Apr 17 Python
keras:model.compile损失函数的用法
Jul 01 Python
获取CSDN文章内容并转换为markdown文本的python
Sep 06 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
ecshop 批量上传(加入自定义属性)
2012/03/20 PHP
php object转数组示例
2014/01/15 PHP
PHP封装的MSSql操作类完整实例
2016/05/26 PHP
PHP利用Socket获取网站的SSL证书与公钥
2017/06/18 PHP
js宝典学习笔记(上)
2007/01/10 Javascript
分享27个jQuery 表单插件集合推荐
2011/04/25 Javascript
javascript和jquery修改a标签的href属性
2013/12/16 Javascript
js操作模态窗口及父子窗口间相互传值示例
2014/06/09 Javascript
javascript实现一个数值加法函数
2015/06/26 Javascript
JS简单测试循环运行时间的方法
2016/09/04 Javascript
把多个JavaScript函数绑定到onload事件处理函数上的方法
2016/09/04 Javascript
WEB开发之注册页面验证码倒计时代码的实现
2016/12/15 Javascript
详谈jQuery.load()和Jsp的include的区别
2017/04/12 jQuery
从零开始学习Node.js系列教程之设置HTTP头的方法示例
2017/04/13 Javascript
Webpack性能优化 DLL 用法详解
2017/08/10 Javascript
webpack打包多页面的方法
2018/11/30 Javascript
python连接MySQL数据库实例分析
2015/05/12 Python
你应该知道的python列表去重方法
2017/01/17 Python
Python开发SQLite3数据库相关操作详解【连接,查询,插入,更新,删除,关闭等】
2017/07/27 Python
tensorflow 输出权重到csv或txt的实例
2018/06/14 Python
[机器视觉]使用python自动识别验证码详解
2019/05/16 Python
PyCharm 2019.3发布增加了新功能一览
2019/12/08 Python
Python request操作步骤及代码实例
2020/04/13 Python
CSS3实例分享--超炫checkbox复选框和radio单选框
2014/09/01 HTML / CSS
罗技英国官方网站:Logitech UK
2020/11/03 全球购物
城市轨道交通工程职业规划书范文
2014/01/18 职场文书
毕业生如何写自荐信
2014/03/26 职场文书
供应链金融服务方案
2014/05/25 职场文书
党员批评与自我批评思想汇报(集锦)
2014/09/14 职场文书
2015年销售助理工作总结
2015/05/11 职场文书
2015企业年终工作总结范文
2015/05/27 职场文书
中学生运动会广播稿
2015/08/19 职场文书
《去年的树》教学反思
2016/02/18 职场文书
Python编程编写完善的命令行工具
2021/09/15 Python
Windows环境下实现批量执行Sql文件
2021/10/05 SQL Server
SpringBoot 集成短信和邮件 以阿里云短信服务为例
2022/04/22 Java/Android