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实现telnet客户端的方法
Apr 15 Python
python追加元素到列表的方法
Jul 28 Python
python变量不能以数字打头详解
Jul 06 Python
Windows中使用wxPython和py2exe开发Python的GUI程序的实例教程
Jul 11 Python
Python科学计算包numpy用法实例详解
Feb 08 Python
Python多线程threading模块用法实例分析
May 22 Python
python pprint模块中print()和pprint()两者的区别
Feb 10 Python
pycharm快捷键汇总
Feb 14 Python
Python configparser模块封装及构造配置文件
Aug 07 Python
Python制作一个仿QQ办公版的图形登录界面
Sep 22 Python
利用python做表格数据处理
Apr 13 Python
python语言中pandas字符串分割str.split()函数
Aug 05 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
php使用redis的有序集合zset实现延迟队列应用示例
2020/02/20 PHP
JS获取父节点方法
2009/08/20 Javascript
javascript实现的基于金山词霸网络翻译的代码
2010/01/15 Javascript
jquery select下拉框操作的一些说明
2010/04/02 Javascript
Kibo 用于处理键盘事件的Javascript工具库
2011/10/28 Javascript
实现JavaScript的组成----BOM和DOM详解
2016/05/18 Javascript
JS获取当前页面名称的简单实例
2016/08/19 Javascript
javascript简单实现跟随滚动条漂浮的返回顶部按钮效果
2016/08/19 Javascript
js实现可输入可选择的select下拉框
2016/12/21 Javascript
Vue.js使用$.ajax和vue-resource实现OAuth的注册、登录、注销和API调用
2017/05/10 Javascript
node.js中cluster的使用教程
2017/06/09 Javascript
日期时间范围选择插件:daterangepicker使用总结(必看篇)
2017/09/14 Javascript
完美解决手机浏览器顶部下拉出现网页源或刷新的问题
2017/11/30 Javascript
Vue 进入/离开动画效果
2017/12/26 Javascript
vue实现点击关注后及时更新列表功能
2018/06/26 Javascript
小程序实现自定义导航栏适配完美版
2019/04/02 Javascript
Python实现的多线程http压力测试代码
2017/02/08 Python
django认证系统实现自定义权限管理的方法
2018/07/16 Python
python实现输入的数据在地图上生成热力图效果
2019/12/06 Python
TensorFlow MNIST手写数据集的实现方法
2020/02/05 Python
解决pycharm每次打开项目都需要配置解释器和安装库问题
2020/02/26 Python
python小技巧——将变量保存在本地及读取
2020/11/13 Python
jupyter notebook远程访问不了的问题解决方法
2021/01/11 Python
mui几种页面跳转方式对比总结概括
2017/08/18 HTML / CSS
Html5定位终极解决方案
2020/02/05 HTML / CSS
阿拉伯时尚购物网站:Nisnass
2021/02/07 全球购物
领先的荷兰线上超市:荷兰之家Holland at Home(支持中文)
2021/01/21 全球购物
运动会入场词100字
2014/02/06 职场文书
文员转正自我鉴定怎么写
2014/09/29 职场文书
2014年企业员工工作总结
2014/12/09 职场文书
投标单位介绍信
2015/05/05 职场文书
宣传部部长竞选稿
2015/11/21 职场文书
驾驶员安全责任协议书
2016/03/22 职场文书
2020年个人安全保证书参考模板
2020/01/08 职场文书
总结Python使用过程中的bug
2021/06/18 Python
理解python中装饰器的作用
2021/07/21 Python