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入门指引
Apr 01 Python
python删除指定类型(或非指定)的文件实例详解
Jul 06 Python
Python使用中文正则表达式匹配指定中文字符串的方法示例
Jan 20 Python
python网络爬虫之如何伪装逃过反爬虫程序的方法
Nov 23 Python
Python登录并获取CSDN博客所有文章列表代码实例
Dec 28 Python
Python利用openpyxl库遍历Sheet的实例
May 03 Python
Python闭包函数定义与用法分析
Jul 20 Python
django使用admin站点上传图片的实例
Jul 28 Python
pytorch torch.expand和torch.repeat的区别详解
Nov 05 Python
Python numpy线性代数用法实例解析
Nov 15 Python
python实现宿舍管理系统
Nov 22 Python
Python使用socketServer包搭建简易服务器过程详解
Jun 12 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
造势之举?韩国总统候选人发布《星际争霸》地图
2017/04/22 星际争霸
PHP下利用header()函数设置浏览器缓存的代码
2010/09/01 PHP
PHP实现财务审核通过后返现金额到客户的功能
2019/07/04 PHP
JavaScript在XHTML中的用法详解
2013/04/11 Javascript
JavaScript汉诺塔问题解决方法
2015/04/21 Javascript
Backbone.js 0.9.2 源码注释中文翻译版
2015/06/25 Javascript
jQuery旋转木马式幻灯片轮播特效
2015/12/04 Javascript
jQuery联动日历的实例解析
2016/12/02 Javascript
jfinal与bootstrap的登出实战详解
2017/11/27 Javascript
Angular实现较为复杂的表格过滤,删除功能示例
2017/12/23 Javascript
JavaScript的Object.defineProperty详解
2018/07/09 Javascript
解决vue 引入子组件报错的问题
2018/09/06 Javascript
vue this.reload 方法 配置
2018/09/12 Javascript
vue-cli的build的文件夹下没有dev-server.js文件配置mock数据的方法
2019/04/17 Javascript
koa router 多文件引入的方法示例
2019/05/22 Javascript
jquery传参及获取方式(两种方式)
2020/02/13 jQuery
如何实现小程序与小程序之间的跳转
2020/11/04 Javascript
[49:31]DOTA2-DPC中国联赛 正赛 Elephant vs LBZS BO3 第二场 1月29日
2021/03/11 DOTA
跟老齐学Python之玩转字符串(2)更新篇
2014/09/28 Python
centos 下面安装python2.7 +pip +mysqld
2014/11/18 Python
设计模式中的原型模式在Python程序中的应用示例
2016/03/02 Python
详解Python函数式编程—高阶函数
2019/03/29 Python
python实现按行分割文件
2019/07/22 Python
详解Django3中直接添加Websockets方式
2020/02/12 Python
利用CSS3的特性改变文本选中时的颜色
2013/09/11 HTML / CSS
美国领先的医疗警报服务:Philips Lifeline
2018/03/12 全球购物
美国顶级水上运动专业店:Marine Products
2018/04/15 全球购物
初中生期末考试的自我评价
2013/12/17 职场文书
幼儿园保教管理制度
2014/02/03 职场文书
幼儿园优秀班主任事迹材料
2014/05/14 职场文书
创先争优公开承诺书
2014/08/30 职场文书
四风查摆剖析材料
2014/10/10 职场文书
领导班子整改措施
2014/10/24 职场文书
教师工作表现自我评价
2015/03/05 职场文书
邹越演讲观后感
2015/06/15 职场文书
详解Python+OpenCV进行基础的图像操作
2022/02/15 Python