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 实现微信跳一跳(Mac+iOS版)
Jan 04 Python
unittest+coverage单元测试代码覆盖操作实例详解
Apr 04 Python
使用TensorFlow实现SVM
Sep 06 Python
python 高效去重复 支持GB级别大文件的示例代码
Nov 08 Python
python3+PyQt5 实现Rich文本的行编辑方法
Jun 17 Python
python re模块匹配贪婪和非贪婪模式详解
Feb 11 Python
Python使用configparser库读取配置文件
Feb 22 Python
jupyternotebook 撤销删除的操作方式
Apr 17 Python
Python decimal模块使用方法详解
Jun 08 Python
Python发送邮件实现基础解析
Aug 14 Python
详解Django的MVT设计模式
Apr 29 Python
Python 如何将integer转化为罗马数(3999以内)
Jun 05 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数组函数序列之asort() - 对数组的元素值进行升序排序,保持索引关系
2011/11/02 PHP
PHP图片处理之使用imagecopyresampled函数实现图片缩放例子
2014/11/19 PHP
PHP7 mongoDB扩展使用的方法分享
2019/05/02 PHP
线路分流自动跳转代码;希望对大家有用!
2006/12/02 Javascript
JavaScript Event学习第十一章 按键的检测
2010/02/10 Javascript
javascript new fun的执行过程
2010/08/05 Javascript
jQuery学习笔记(1)--用jQuery实现异步通信(用json传值)具体思路
2013/04/08 Javascript
解决jquery版本冲突的有效方法
2014/09/02 Javascript
jQuery替换textarea中换行的方法
2015/06/10 Javascript
基于jQuery和hwSlider实现内容左右滑动切换效果附源码下载(一)
2016/06/22 Javascript
Bootstrap模态框(modal)垂直居中的实例代码
2016/08/18 Javascript
微信小程序 教程之wxapp视图容器 scroll-view
2016/10/19 Javascript
JavaScript中日常收集常见的10种错误(推荐)
2017/01/08 Javascript
NodeJs安装npm包一直失败的解决方法
2017/04/28 NodeJs
vue-router的两种模式的区别
2019/05/30 Javascript
Node.js学习教程之Module模块
2019/09/03 Javascript
js之切换全屏和退出全屏实现代码实例
2019/09/09 Javascript
Vue 自定义标签的src属性不能使用相对路径的解决
2019/09/17 Javascript
利用JS代码自动删除稿件的普通弹幕功能
2019/09/20 Javascript
vue.js循环radio的实例
2019/11/07 Javascript
javascript实现视频弹幕效果(两个版本)
2019/11/28 Javascript
Python中optionParser模块的使用方法实例教程
2014/08/29 Python
Python中atexit模块的基本使用示例
2015/07/08 Python
Python 实现「食行生鲜」签到领积分功能
2018/09/26 Python
详解Python函数式编程—高阶函数
2019/03/29 Python
Django框架模板文件使用及模板文件加载顺序分析
2019/05/23 Python
Keras自动下载的数据集/模型存放位置介绍
2020/06/19 Python
通过自学python能找到工作吗
2020/06/21 Python
Python利用imshow制作自定义渐变填充柱状图(colorbar)
2020/12/10 Python
索桥的故事教学反思
2014/02/06 职场文书
普通话宣传标语
2014/06/26 职场文书
关于安全的广播稿
2014/10/23 职场文书
务虚会发言材料
2014/12/25 职场文书
2015年收银工作总结范文
2015/04/01 职场文书
工厂采购员岗位职责
2015/04/07 职场文书
html5+实现plus.io进行拍照和图片等获取
2022/06/01 HTML / CSS