python仿抖音表白神器


Posted in Python onApril 08, 2019

Python能够干嘛?

可以做日常任务,比如自动备份你的MP3;
可以做网站,很多著名的网站像知乎、YouTube就是Python写的;
可以做网络游戏的后台,很多在线游戏的后台都是Python开发的。

上面说的这些本人并没有实现过;

但是我知道Python可以做一些有趣的东西,比如仿制抖音表白小软件;

python仿抖音表白神器

本人也是刚刚学习Python,这个脚本通过百度找到的,然后自己也重新写了一遍,加深了映像,最主要的还是思路要清晰;

流程:

1、创建一个游戏屏幕
2、加载title
3、加载button,
4、当鼠标移动到 '算了吧' 上面的时候 重加加载桌面并随机生成一个 '算了吧' 坐标;
5、当鼠标移动到 ‘好呀'上面时 显示不同的title

以下就是Python脚本:

import pygame
import random
 
 
# 设置游戏屏幕大小 这是一个常量
WIDTH, HEIGHT = 640, 480
 
screen = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32)
pygame.display.set_caption('FROM一个喜欢你很久的小哥哥')
 
# 标题
def title(text, screen, scale, color=(255, 0, 0)):
 font = pygame.font.SysFont('SimHei', 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)
 
 # 初始化文字的坐标
 screen.blit(textRender, (WIDTH/scale[0], HEIGHT/scale[1]))
 
# 按钮
def button(text, x, y, w, h, color, screen):
 pygame.draw.rect(screen, color, (x, y, w, h))
 font = pygame.font.SysFont('SimHei', 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 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((255, 255, 255))
 font = pygame.font.SysFont('SimHei', 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 == pygame.QUIT:
    pygame.quit()
 
def main():
 pygame.init()
 clock = pygame.time.Clock()
 unlike_pos_x = 330
 unlike_pos_y = 250
 unlike_pos_width = 80
 unlike_pos_height = 40
 unlike_color = (0, 191, 255)
 
 like_pos_x = 180
 like_pos_y = 250
 like_pos_width = 80
 like_pos_height = 40
 like_color = (0, 191, 255)
 
 running = True
 while running:
  # 填充窗口
  screen.fill((255, 255, 255))
 
  img = pygame.image.load('d:/love2.png')
  imgRect = img.get_rect()
  imgRect.midtop = int(WIDTH / 1.3), HEIGHT // 7
  screen.blit(img, imgRect)
 
  # 获取坐标
  pos = pygame.mouse.get_pos()
  if pos[0] < unlike_pos_x + unlike_pos_width + 5 and pos[0] > unlike_pos_x - 5 and pos[1] < unlike_pos_y + unlike_pos_height + 5 and pos[1] > unlike_pos_y - 5:
   while True:
    unlike_pos_x, unlike_pos_y = get_random_pos()
    if pos[0] < unlike_pos_x + unlike_pos_width + 5 and pos[
     0] > unlike_pos_x - 5 and \
     pos[1] < unlike_pos_y + unlike_pos_height + 5 and pos[
     1] > unlike_pos_y - 5:
     continue
    break
 
  title('小姐姐,我观察你很久了', screen, scale=[5, 8])
  title('做我女朋友好不好呀', screen, scale=[5, 4])
  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, unlike_color, screen)
 
  for event in pygame.event.get():
   if event.type == pygame.QUIT:
    pygame.quit()
 
  if pos[0] < like_pos_x + like_pos_width + 5 and pos[0] > like_pos_x - 5 and pos[1] < like_pos_y + like_pos_height + 5 and pos[1] > like_pos_y - 5:
   show_like_interface('我就知道小姐姐你也喜欢我~', screen, color=(255, 0, 0))
 
  pygame.display.flip()
  pygame.display.update()
  clock.tick(60)
 
 
main()

大家有好的创意也可以一起交流下;

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python中生成器和迭代器的区别详解
Feb 10 Python
python中字符串的操作方法大全
Jun 03 Python
pandas.dataframe中根据条件获取元素所在的位置方法(索引)
Jun 07 Python
DataFrame:通过SparkSql将scala类转为DataFrame的方法
Jan 29 Python
python读取csv和txt数据转换成向量的实例
Feb 12 Python
django配置连接数据库及原生sql语句的使用方法
Mar 03 Python
Python中低维数组填充高维数组的实现
Dec 02 Python
python 递归调用返回None的问题及解决方法
Mar 16 Python
python requests包的request()函数中的参数-params和data的区别介绍
May 05 Python
PyTorch-GPU加速实例
Jun 23 Python
在pycharm中使用pipenv创建虚拟环境和安装django的详细教程
Nov 30 Python
Python何绘制带有背景色块的折线图
Apr 23 Python
Python面向对象程序设计之私有属性及私有方法示例
Apr 08 #Python
分析经典Python开发工程师面试题
Apr 08 #Python
django celery redis使用具体实践
Apr 08 #Python
python制作抖音代码舞
Apr 07 #Python
python实现抖音点赞功能
Apr 07 #Python
将pip源更换到国内镜像的详细步骤
Apr 07 #Python
python实现弹窗祝福效果
Apr 07 #Python
You might like
咖啡的植物学知识
2021/03/03 咖啡文化
使用PHP+Redis实现延迟任务,实现自动取消订单功能
2019/11/21 PHP
贴一个在Mozilla中常用的Javascript代码
2007/01/09 Javascript
小型js框架veryide.librar源代码
2009/03/05 Javascript
基于jquery的cookie的用法
2011/01/10 Javascript
Jquery下EasyUI组件中的DataGrid结果集清空方法
2014/01/06 Javascript
JavaScript字符串对象substr方法入门实例(用于截取字符串)
2014/10/16 Javascript
利用jquery操作Radio方法小结
2014/10/20 Javascript
jQuery过滤选择器用法分析
2015/02/10 Javascript
jQuery使用hide方法隐藏指定元素class样式用法实例
2015/03/30 Javascript
js+canvas绘制矩形的方法
2016/01/28 Javascript
深入理解Vue transition源码分析
2017/07/30 Javascript
jQuery插件DataTables分页开发心得体会
2017/08/22 jQuery
vue todo-list组件发布到npm上的方法
2018/04/04 Javascript
说说如何利用 Node.js 代理解决跨域问题
2019/04/22 Javascript
JS 遍历 json 和 JQuery 遍历json操作完整示例
2019/11/11 jQuery
Vue实现商品飞入购物车效果(电商项目)
2019/11/26 Javascript
python抓取网页内容并进行语音播报的方法
2018/12/24 Python
python基于TCP实现的文件下载器功能案例
2019/12/10 Python
把Anaconda中的环境导入到Pycharm里面的方法步骤
2020/10/30 Python
Python使用windows设置定时执行脚本
2020/11/12 Python
详解Python中的文件操作
2021/01/14 Python
浅谈CSS3 box-sizing 属性 有趣的盒模型
2019/04/02 HTML / CSS
全球在线商店:BerryLook
2019/04/14 全球购物
美国折扣地毯销售网站:Rugs.com
2020/03/27 全球购物
EJB包括(SessionBean,EntityBean)说出他们的生命周期,及如何管理事务的?
2013/02/17 面试题
Unix里面如何在后台运行程序
2016/10/14 面试题
历史系毕业生自荐信
2013/10/28 职场文书
《猴子种树》教学反思
2014/02/14 职场文书
党员岗位承诺口号大全
2014/03/28 职场文书
预备党员自我评价范文
2015/03/04 职场文书
升学宴祝酒词
2015/08/11 职场文书
禁毒心得体会范文
2016/01/15 职场文书
如何把新闻人物写得立体、鲜活?
2019/08/14 职场文书
FP-growth算法发现频繁项集——发现频繁项集
2021/06/24 Python
PostgreSQL出现死锁该如何解决
2022/05/30 PostgreSQL