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中的zip函数使用示例
Jan 29 Python
Python删除空文件和空文件夹的方法
Jul 14 Python
Python减少循环层次和缩进的技巧分析
Mar 15 Python
Python中property函数用法实例分析
Jun 04 Python
django基于存储在前端的token用户认证解析
Aug 06 Python
对python中的os.getpid()和os.fork()函数详解
Aug 08 Python
关于python中plt.hist参数的使用详解
Nov 28 Python
Django自带的加密算法及加密模块详解
Dec 03 Python
如何基于python操作json文件获取内容
Dec 24 Python
浅谈python多线程和多线程变量共享问题介绍
Apr 17 Python
python3实现简单飞机大战
Nov 29 Python
Pandas DataFrame求差集的示例代码
Dec 13 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
德生H-501的评价与改造
2021/03/02 无线电
php中突破基于HTTP_REFERER的防盗链措施(stream_context_create)
2011/03/29 PHP
php版微信公众平台实现预约提交后发送email的方法
2016/09/26 PHP
详解PHP发送邮件知识点
2018/05/06 PHP
模仿JQuery sortable效果 代码有错但值得看看
2009/11/05 Javascript
深入理解JavaScript作用域和作用域链
2011/10/21 Javascript
JavaScript中如何通过arguments对象实现对象的重载
2014/05/12 Javascript
windows8.1+iis8.5下安装node.js开发环境
2014/12/12 Javascript
JavaScript设计模式之外观模式介绍
2014/12/28 Javascript
基于vue.js实现侧边菜单栏
2017/03/20 Javascript
对Angular中单向数据流的深入理解
2018/03/31 Javascript
pm2发布node配置文件ecosystem.json详解
2019/05/15 Javascript
vue+Element-ui实现分页效果
2020/11/15 Javascript
js实现简单商品筛选功能
2021/02/02 Javascript
vue-cli 3如何使用vue-bootstrap-datetimepicker日期插件
2021/02/20 Vue.js
Python环境下搭建属于自己的pip源的教程
2016/05/05 Python
详解Python 序列化Serialize 和 反序列化Deserialize
2017/08/20 Python
python调用OpenCV实现人脸识别功能
2018/05/25 Python
python url 参数修改方法
2018/12/26 Python
使用Python自动化破解自定义字体混淆信息的方法实例
2019/02/13 Python
python有序查找算法 二分法实例解析
2020/02/18 Python
python中if及if-else如何使用
2020/06/02 Python
在Mac中配置Python虚拟环境过程解析
2020/06/22 Python
python一些性能分析的技巧
2020/08/30 Python
CSS3实现歌词进度文字颜色填充变化动态效果的思路详解
2020/06/02 HTML / CSS
Html5踩坑记之mandMobile使用小记
2020/04/02 HTML / CSS
aden + anais官方网站:婴儿襁褓、毯子、尿布和服装
2017/06/21 全球购物
美国领先的在线旅游网站:Orbitz
2018/11/05 全球购物
英国手机壳购买网站:Case Hut
2019/04/11 全球购物
平面设计自荐信
2013/10/07 职场文书
酒店管理专业毕业生推荐信
2013/11/10 职场文书
中学教师教育感言
2014/02/21 职场文书
三八红旗手先进事迹材料
2014/05/13 职场文书
争先创优演讲稿
2014/09/15 职场文书
2014年学生党支部工作总结
2014/12/20 职场文书
MySQL分区表管理命令汇总
2022/03/21 MySQL