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使用chardet判断字符串编码的方法
Mar 13 Python
python BeautifulSoup设置页面编码的方法
Apr 03 Python
Python删除windows垃圾文件的方法
Jul 14 Python
Python简单实现子网掩码转换的方法
Apr 13 Python
python3.7.0的安装步骤
Aug 27 Python
python广度优先搜索得到两点间最短路径
Jan 17 Python
Python Django框架url反向解析实现动态生成对应的url链接示例
Oct 18 Python
tensorflow实现残差网络方式(mnist数据集)
May 26 Python
PyQt中使用QtSql连接MySql数据库的方法
Jul 28 Python
10行Python代码实现Web自动化管控的示例代码
Aug 14 Python
Python计算矩阵的和积的实例详解
Sep 10 Python
Python绘制散点图之可视化神器pyecharts
Jul 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
咖啡豆要不要放冰箱的原因
2021/03/04 冲泡冲煮
别人整理的服务器变量:$_SERVER
2006/10/20 PHP
第八节--访问方式
2006/11/16 PHP
PHP中如何判断exec函数执行成功?
2016/08/04 PHP
PHP实现普通hash分布式算法简单示例
2018/08/06 PHP
Yii框架中使用PHPExcel的方法分析
2019/07/25 PHP
Locate a File Using a File Open Dialog Box
2007/06/18 Javascript
用JavaScript编写COM组件的步骤
2009/03/17 Javascript
JavaScript高级程序设计 DOM学习笔记
2011/09/10 Javascript
javascript中this做事件参数相关问题解答
2013/03/17 Javascript
JavaScript怎么判断图片是否加载完成以便获取其尺寸
2014/05/08 Javascript
node.js入门教程
2014/06/01 Javascript
只需五句话搞定JavaScript作用域(经典)
2016/07/26 Javascript
JS版微信6.0分享接口用法分析
2016/10/13 Javascript
javascript函数的四种调用模式
2017/01/08 Javascript
Webpack常见静态资源处理-模块加载器(Loaders)+ExtractTextPlugin插件
2017/06/29 Javascript
JavaScript之DOM插入更新删除_动力节点Java学院整理
2017/07/03 Javascript
详解微信小程序中的页面代码中的模板的封装
2017/10/12 Javascript
vue实现配置全局访问路径头(axios)
2019/11/01 Javascript
JS实现扫码枪扫描二维码功能
2020/01/03 Javascript
mpvue实现微信小程序快递单号查询代码
2020/04/03 Javascript
在Vue中使用antv的示例代码
2020/06/29 Javascript
微信小程序实现身份证取景框拍摄
2020/09/09 Javascript
[46:23]完美世界DOTA2联赛PWL S2 FTD vs Magma 第一场 11.20
2020/11/23 DOTA
Python实现读取txt文件并画三维图简单代码示例
2017/12/09 Python
Python实现的txt文件去重功能示例
2018/07/07 Python
pytorch 共享参数的示例
2019/08/17 Python
Django多进程滚动日志问题解决方案
2019/12/17 Python
html5需遵循的6个设计原则
2016/04/27 HTML / CSS
使用layui实现左侧菜单栏及动态操作tab项的方法
2020/11/10 HTML / CSS
NIHAOMARKET官方海外旗舰店:意大利你好华人超市
2018/01/27 全球购物
Java如何调用外部Exe程序
2015/07/04 面试题
领导干部考察材料
2014/02/08 职场文书
干部作风整顿个人剖析材料
2014/10/06 职场文书
2014普法依法治理工作总结
2014/12/18 职场文书
优质服务心得体会(共4篇)
2016/01/22 职场文书