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如何实现远程控制电脑(结合微信)
Dec 21 Python
Python使用os模块和fileinput模块来操作文件目录
Jan 19 Python
浅谈python numpy中nonzero()的用法
Apr 02 Python
Django如何配置mysql数据库
May 04 Python
tensorflow: variable的值与variable.read_value()的值区别详解
Jul 30 Python
python实现的自动发送消息功能详解
Aug 15 Python
python定时任务 sched模块用法实例
Nov 04 Python
浅谈Python里面None True False之间的区别
Jul 09 Python
Python3 ffmpeg视频转换工具使用方法解析
Aug 10 Python
Python Socket多线程并发原理及实现
Dec 11 Python
如何在Python中创建二叉树
Mar 30 Python
python爬虫框架feapde的使用简介
Apr 20 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
新的一年,新的期待:DC在2020年的四部动画电影
2020/01/01 欧美动漫
无数据库的详细域名查询程序PHP版(5)
2006/10/09 PHP
php中大括号作用介绍
2012/03/22 PHP
zend Framework中的Layout(模块化得布局)详解
2013/06/28 PHP
如何阻止网站被恶意反向代理访问(防网站镜像)
2014/03/18 PHP
php each 返回数组中当前的键值对并将数组指针向前移动一步实例
2016/11/22 PHP
php strftime函数获取日期时间(switch用法)
2018/05/16 PHP
用JavaScript脚本实现Web页面信息交互
2006/10/11 Javascript
利用js对象弹出一个层
2008/03/26 Javascript
基于JQuery的密码强度验证代码
2010/03/01 Javascript
javascript右下角弹层及自动隐藏(自己编写)
2013/11/20 Javascript
jquery 图片缩放拖动的简单实例
2014/01/08 Javascript
JS获取表格内指定单元格html内容的方法
2015/03/31 Javascript
jQuery实现的多级下拉菜单效果代码
2015/08/24 Javascript
JS实现漂亮的窗口拖拽效果(可改变大小、最大化、最小化、关闭)
2015/10/10 Javascript
javascript bom是什么及bom和dom的区别
2015/11/26 Javascript
Node.js实现连接mysql数据库功能示例
2017/09/15 Javascript
js 显示日期时间的实例(时间过一秒加1)
2017/10/25 Javascript
详解nuxt sass全局变量(公共scss解决方案)
2018/06/27 Javascript
Vue在页面数据渲染完成之后的调用方法
2018/09/11 Javascript
JS实现网页时钟特效
2020/03/25 Javascript
在Webpack中用url-loader处理图片和字体的问题
2020/04/28 Javascript
python multiprocessing模块用法及原理介绍
2019/08/20 Python
Python实现生成密码字典的方法示例
2019/09/02 Python
python输出pdf文档的实例
2020/02/13 Python
基于Django signals 信号作用及用法详解
2020/03/28 Python
用CSS3实现无限循环的无缝滚动的实例代码
2017/07/04 HTML / CSS
机电专业体育教师求职信
2013/09/21 职场文书
《最后的姿势》教学反思
2014/02/27 职场文书
护士感人事迹
2014/05/01 职场文书
党务公开方案
2014/05/06 职场文书
法制宣传口号
2014/06/16 职场文书
地道战观后感400字
2015/06/04 职场文书
Nginx配置https原理及实现过程详解
2021/03/31 Servers
python中super()函数的理解与基本使用
2021/08/30 Python
Python实现为PDF去除水印的示例代码
2022/04/03 Python