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中的特殊语法:filter、map、reduce、lambda介绍
Apr 14 Python
Python yield 使用浅析
May 28 Python
Flask框架中密码的加盐哈希加密和验证功能的用法详解
Jun 07 Python
在Python dataframe中出生日期转化为年龄的实现方法
Oct 20 Python
pandas通过索引进行排序的示例
Nov 16 Python
Python用61行代码实现图片像素化的示例代码
Dec 10 Python
Python实战购物车项目的实现参考
Feb 20 Python
Python实现线性插值和三次样条插值的示例代码
Nov 13 Python
Python小白不正确的使用类变量实例
May 29 Python
使用Keras预训练好的模型进行目标类别预测详解
Jun 27 Python
Jupyter Notebook添加代码自动补全功能的实现
Jan 07 Python
使用Python+OpenCV进行卡类型及16位卡号数字的OCR功能
Aug 30 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
一个简洁的多级别论坛
2006/10/09 PHP
php数组函数序列之each() - 获取数组当前内部指针所指向元素的键名和键值,并将指针移到下一位
2011/10/31 PHP
php中静态类与静态变量用法的区别分析
2015/01/15 PHP
thinkphp微信开之安全模式消息加密解密不成功的解决办法
2015/12/02 PHP
PHP 实现重载
2021/03/09 PHP
详解javascript中的事件处理
2015/11/06 Javascript
js复制内容到剪贴板代码,js复制代码的简单实例
2016/10/27 Javascript
vue mixins组件复用的几种方式(小结)
2017/09/06 Javascript
vue获取DOM元素并设置属性的两种实现方法
2017/09/30 Javascript
vue 数组和对象不能直接赋值情况和解决方法(推荐)
2017/10/25 Javascript
微信小程序实现下拉框功能
2019/07/16 Javascript
es6中reduce的基本使用方法
2019/09/10 Javascript
element-ui中按需引入的实现
2019/12/25 Javascript
python中pycurl库的用法实例
2014/09/30 Python
Python Matplotlib库入门指南
2015/05/18 Python
Python 装饰器深入理解
2017/03/16 Python
简单易懂的python环境安装教程
2017/07/13 Python
Python中利用aiohttp制作异步爬虫及简单应用
2018/11/29 Python
Django使用AJAX调用自己写的API接口的方法
2019/03/06 Python
Python当中的array数组对象实例详解
2019/06/12 Python
基于树莓派的语音对话机器人
2019/06/17 Python
python networkx 根据图的权重画图实现
2019/07/10 Python
深入了解Python iter() 方法的用法
2019/07/11 Python
如何利用Python matplotlib绘制雷达图
2020/12/21 Python
Html5自定义字体解决方法
2019/10/09 HTML / CSS
小女主人连衣裙:Little Mistress
2017/07/10 全球购物
Ellesse英国官网:意大利高级运动品牌
2019/07/23 全球购物
岗位职责定义及内容
2013/11/08 职场文书
高中毕业自我鉴定
2013/12/13 职场文书
幼儿园教师培训方案
2014/02/04 职场文书
班级读书活动总结
2014/06/30 职场文书
我的中国梦演讲稿800字
2014/08/19 职场文书
2014年建筑工作总结
2014/11/26 职场文书
廉洁自律承诺书范文
2015/04/28 职场文书
员工福利申请报告
2015/05/15 职场文书
Win11 22H2 2022怎么更新? 获得Win1122H22022版本升级技巧
2022/09/23 数码科技