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实现同时兼容老版和新版Socket协议的一个简单WebSocket服务器
Jun 04 Python
Python3里的super()和__class__使用介绍
Apr 23 Python
Python中random模块生成随机数详解
Mar 10 Python
python学习之面向对象【入门初级篇】
Jan 21 Python
Python实现生成随机日期字符串的方法示例
Dec 25 Python
django 2.0更新的10条注意事项总结
Jan 05 Python
神经网络(BP)算法Python实现及应用
Apr 16 Python
基于python的多进程共享变量正确打开方式
Apr 28 Python
解决PyCharm import torch包失败的问题
Oct 13 Python
python实现从pdf文件中提取文本,并自动翻译的方法
Nov 28 Python
Python定时发送天气预报邮件代码实例
Sep 09 Python
python正则表达式 匹配反斜杠的操作方法
Aug 07 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 导出Excel示例分享
2014/08/18 PHP
PHP关于foreach复制知识点总结
2019/01/28 PHP
Laravel框架集合用法实例浅析
2020/05/14 PHP
js鼠标点击图片实现随机变换图片的方法
2015/02/16 Javascript
JS实现控制表格行内容垂直对齐的方法
2015/03/30 Javascript
Express实现前端后端通信上传图片之存储数据库(mysql)傻瓜式教程(一)
2015/12/10 Javascript
使用JavaScript解决网页图片拉伸问题(推荐)
2016/11/25 Javascript
js仿微信抢红包功能
2020/09/25 Javascript
在 Angular中 使用 Lodash 的方法
2018/02/11 Javascript
新手必须知的Node.js 4个JavaScript基本概念
2018/09/16 Javascript
详解Vue的常用指令v-if, v-for, v-show,v-else, v-bind, v-on
2018/10/12 Javascript
iview的table组件自带的过滤器实现
2019/07/12 Javascript
javascript事件监听与事件委托实例详解
2019/08/16 Javascript
p5.js实现故宫橘猫赏秋图动画
2019/10/23 Javascript
vue Treeselect下拉树只能选择第N级元素实现代码
2020/08/31 Javascript
如何使用 JavaScript 操作浏览器历史记录 API
2020/11/24 Javascript
[59:30]VG vs LGD 2019国际邀请赛淘汰赛 胜者组 BO3 第二场 8.22
2019/09/05 DOTA
跟老齐学Python之复习if语句
2014/10/02 Python
在Python中调用ggplot的三种方法
2015/04/08 Python
Python实现随机生成手机号及正则验证手机号的方法
2018/04/25 Python
详解Django解决ajax跨域访问问题
2018/08/24 Python
Python函数式编程实例详解
2020/01/17 Python
Python连接Hadoop数据中遇到的各种坑(汇总)
2020/04/14 Python
css3 flex实现div内容水平垂直居中的几种方法
2020/03/27 HTML / CSS
HTML5+CSS3:3D展示商品信息示例
2017/01/03 HTML / CSS
一套PHP的笔试题
2013/05/31 面试题
报关简历自我评价怎么写
2013/09/19 职场文书
客服专员岗位职责范本
2013/11/29 职场文书
后勤采购员岗位职责
2013/12/19 职场文书
差生评语大全
2014/05/04 职场文书
2015年为民办实事工作总结
2015/05/26 职场文书
英文投诉信格式
2015/07/03 职场文书
又涨知识了,自律到底多重要?
2019/06/27 职场文书
一文搞懂如何实现Go 超时控制
2021/03/30 Python
golang在GRPC中设置client的超时时间
2021/04/27 Golang
SpringBoot工程下使用OpenFeign的坑及解决
2021/07/02 Java/Android