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 05 Python
Python中如何优雅的合并两个字典(dict)方法示例
Aug 09 Python
Pandas统计重复的列里面的值方法
Jan 30 Python
解决python tkinter界面卡死的问题
Jul 17 Python
关于python3中setup.py小概念解析
Aug 22 Python
Python Opencv提取图片中某种颜色组成的图形的方法
Sep 19 Python
python实现输入的数据在地图上生成热力图效果
Dec 06 Python
python selenium实现发送带附件的邮件代码实例
Dec 10 Python
Python 捕获代码中所有异常的方法
Aug 03 Python
Python实现扫码工具的示例代码
Oct 09 Python
Python爬虫+Tkinter制作一个翻译软件的示例
Feb 20 Python
opencv读取视频并保存图像的方法
Jun 04 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
re0第二季蕾姆被制作组打入冷宫!艾米莉亚女主扶正,原因唏嘘
2020/04/02 日漫
PHP通过COM使用ADODB的简单例子
2006/12/31 PHP
解析PHP自带的进位制之间的转换函数
2013/06/08 PHP
ThinkPHP之M方法实例详解
2014/06/20 PHP
php使用str_shuffle()函数生成随机字符串的方法分析
2017/02/17 PHP
Laravel下生成验证码的类
2017/11/15 PHP
解决FireFox下[使用event很麻烦]的问题
2006/11/26 Javascript
简洁短小的 JavaScript IE 浏览器判定代码
2010/03/21 Javascript
javascript 原型链维护和继承详解
2014/11/26 Javascript
使用javascript实现Iframe自适应高度
2014/12/24 Javascript
js实现的后台左侧管理菜单代码
2015/09/11 Javascript
canvas仿iwatch时钟效果
2017/03/06 Javascript
浅谈Node.js ORM框架Sequlize之表间关系
2017/07/24 Javascript
Angular2里获取(input file)上传文件的内容的方法
2017/09/05 Javascript
angular.js和vue.js中实现函数去抖示例(debounce)
2018/01/18 Javascript
vue-cli基础配置及webpack配置修改的完整步骤
2019/10/20 Javascript
详解node登录接口之密码错误限制次数(含代码)
2019/10/25 Javascript
python自动化测试之连接几组测试包实例
2014/09/28 Python
python实时分析日志的一个小脚本分享
2017/05/07 Python
Python多进程池 multiprocessing Pool用法示例
2018/09/07 Python
美国时尚女装在线:Missguided
2016/12/03 全球购物
潘多拉意大利官方网上商城:网上选购PANDORA珠宝
2018/10/07 全球购物
Marlies Dekkers内衣美国官方网上商店:高端内衣品牌
2018/11/12 全球购物
Skechers越南官方网站:来自美国的运动休闲品牌
2021/02/22 全球购物
护理专科毕业推荐信
2013/11/10 职场文书
高考备战决心书
2014/03/11 职场文书
铁路安全事故反思
2014/04/26 职场文书
体现团队精神的口号
2014/06/06 职场文书
市场营销毕业求职信
2014/08/07 职场文书
企业法人授权委托书
2014/09/25 职场文书
正风肃纪剖析材料
2014/09/30 职场文书
毕业生就业推荐表自我评价
2015/03/02 职场文书
2016教师读书思廉心得体会
2016/01/23 职场文书
Springboot配置suffix指定mvc视图的后缀方法
2021/07/03 Java/Android
Java无向树分析 实现最小高度树
2022/04/09 Javascript
怎么禁用Win11输入法 最新Win11输入法关闭教程
2022/08/05 数码科技