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 splitlines使用技巧
Sep 06 Python
Python多线程编程(八):使用Event实现线程间通信
Apr 05 Python
python定时检查某个进程是否已经关闭的方法
May 20 Python
Python处理文本文件中控制字符的方法
Feb 07 Python
Python Socket编程详细介绍
Mar 23 Python
Python入门_浅谈数据结构的4种基本类型
May 16 Python
python如何使用unittest测试接口
Apr 04 Python
python os.path模块常用方法实例详解
Sep 16 Python
Python pandas对excel的操作实现示例
Jul 21 Python
python Timer 类使用介绍
Dec 28 Python
python 统计list中各个元素出现的次数的几种方法
Feb 20 Python
Python+Appium自动化测试的实战
Jun 30 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
第六节--访问属性和方法
2006/11/16 PHP
PHP+Memcache实现wordpress访问总数统计(非插件)
2014/07/04 PHP
ThinkPHP中ajax使用实例教程
2014/08/22 PHP
Symfony2框架创建项目与模板设置实例详解
2016/03/17 PHP
PHP面向对象程序设计方法实例详解
2016/12/24 PHP
Laravel框架实现的使用smtp发送邮件功能示例
2019/03/12 PHP
理解Javascript_12_执行模型浅析
2010/10/18 Javascript
15个款优秀的 jQuery 图片特效插件推荐
2011/11/21 Javascript
jquery获得keycode的示例代码
2013/12/30 Javascript
JS实现FLASH幻灯片图片切换效果的方法
2015/03/04 Javascript
JS实现鼠标滑过折叠与展开菜单效果代码
2015/09/06 Javascript
AngularJS 与百度地图的结合实例
2016/10/20 Javascript
angularjs+bootstrap菜单的使用示例代码
2017/03/07 Javascript
Vue中建立全局引用或者全局命令的方法
2017/08/21 Javascript
Bootstrap Tooltip显示换行和左对齐的解决方案
2017/10/11 Javascript
vue-cli项目中使用公用的提示弹层tips或加载loading组件实例详解
2018/05/28 Javascript
如何在微信小程序中存setStorage
2019/12/13 Javascript
js实现拖拽与碰撞检测
2020/09/18 Javascript
三剑客:offset、client和scroll还傻傻分不清?
2020/12/04 Javascript
Nest.js环境变量配置与序列化详解
2021/02/21 Javascript
python使用urllib模块开发的多线程豆瓣小站mp3下载器
2014/01/16 Python
Python使用pip安装报错:is not a supported wheel on this platform的解决方法
2018/01/23 Python
python实现文件的备份流程详解
2019/06/18 Python
PyQt5+python3+pycharm开发环境配置教程
2020/03/24 Python
Python容器类型公共方法总结
2020/08/19 Python
CSS3动画和HTML5新特性详解
2020/08/31 HTML / CSS
FC-Moto美国:欧洲最大的摩托车服装和头盔商店之一
2019/08/24 全球购物
美国在线和移动免费会员制批发零售商:Boxed(移动端的Costco)
2020/01/02 全球购物
网络教育毕业生自我鉴定
2013/10/10 职场文书
年度考核评语
2014/01/19 职场文书
内蒙古鄂尔多斯市市长寄语
2014/04/10 职场文书
《一个小村庄的故事》教学反思
2014/04/13 职场文书
办护照工作证明
2014/10/01 职场文书
大学生上课迟到检讨书
2014/10/15 职场文书
在redisCluster中模糊获取key方式
2021/07/09 Redis
部分武汉产收音机展览
2022/04/07 无线电