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导出Excel图表以及导出为图片的方法
Nov 07 Python
python实现爬虫统计学校BBS男女比例(一)
Dec 31 Python
详解C++编程中一元运算符的重载
Jan 19 Python
Python实例一个类背后发生了什么
Feb 09 Python
基于ID3决策树算法的实现(Python版)
May 31 Python
python pandas 对series和dataframe的重置索引reindex方法
Jun 07 Python
Python第三方库face_recognition在windows上的安装过程
May 03 Python
Python实现语音识别和语音合成功能
Sep 20 Python
Python读取YAML文件过程详解
Dec 30 Python
Pytorch在NLP中的简单应用详解
Jan 08 Python
django 模型中的计算字段实例
May 19 Python
Django创建一个后台的基本步骤记录
Oct 02 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下通过POST还是GET来传值
2008/06/05 PHP
php 调用远程url的六种方法小结
2009/11/02 PHP
php 删除目录下N分钟前创建的所有文件的实现代码
2013/08/10 PHP
正确的PHP匹配UTF-8中文的正则表达式
2015/05/13 PHP
php微信公众平台开发之获取用户基本信息
2015/08/17 PHP
laravel手动创建数组分页的实现代码
2018/06/07 PHP
jquery之别踩白块游戏的简单实现
2016/07/25 Javascript
动态生成的DOM不会触发onclick事件的原因及解决方法
2016/08/06 Javascript
js实现音频控制进度条功能
2017/04/01 Javascript
js生成word中图片处理方法
2018/01/06 Javascript
Angular5中状态管理的实现
2018/09/03 Javascript
关于在vue 中使用百度ueEditor编辑器的方法实例代码
2018/09/14 Javascript
JS实现小米轮播图
2020/09/21 Javascript
[03:49]DOTA2 2015国际邀请赛中国区预选赛第二日现场百态
2015/05/27 DOTA
Python 专题二 条件语句和循环语句的基础知识
2017/03/19 Python
Python解惑之True和False详解
2017/04/24 Python
Python实现OpenCV的安装与使用示例
2018/03/30 Python
如何用Python合并lmdb文件
2018/07/02 Python
Python直接赋值、浅拷贝与深度拷贝实例分析
2019/06/18 Python
django项目简单调取百度翻译接口的方法
2019/08/06 Python
python实现两个文件夹的同步
2019/08/29 Python
python将四元数变换为旋转矩阵的实例
2019/12/04 Python
将python依赖包打包成window下可执行文件bat方式
2019/12/26 Python
python数据预处理 :样本分布不均的解决(过采样和欠采样)
2020/02/29 Python
使用HTML5中的contentEditable来将多行文本自动增高
2016/03/01 HTML / CSS
外贸公司实习自我鉴定
2013/09/24 职场文书
七一党建活动方案
2014/01/28 职场文书
大三学生做职业规划:给未来找个方向
2014/02/24 职场文书
社区工作者感言
2014/03/02 职场文书
新闻人物通讯稿
2014/10/09 职场文书
环卫工作汇报材料
2014/10/28 职场文书
2015年求职自荐信范文
2015/03/04 职场文书
环保建议书作文300字
2015/09/14 职场文书
Nginx进程调度问题详解
2021/09/25 Servers
tomcat的catalina.out日志按自定义时间格式进行分割的操作方法
2022/04/02 Servers
Python3使用Qt5来实现简易的五子棋小游戏
2022/05/02 Python