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之有容乃大的list(1)
Sep 14 Python
Python基于pycrypto实现的AES加密和解密算法示例
Apr 10 Python
Python3之读取连接过的网络并定位的方法
Apr 22 Python
Python3.6简单反射操作示例
Jun 14 Python
简单了解python关系(比较)运算符
Jul 08 Python
Python collections中的双向队列deque简单介绍详解
Nov 04 Python
Python解析json代码实例解析
Nov 25 Python
关于Python 中的时间处理包datetime和arrow的方法详解
Mar 19 Python
opencv python 图片读取与显示图片窗口未响应问题的解决
Apr 24 Python
python 制作磁力搜索工具
Mar 04 Python
Pycharm 如何设置HTML文件自动补全代码或标签
May 21 Python
python脚本框架webpy的url映射详解
Nov 20 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 和 XML: 使用expat函数(一)
2006/10/09 PHP
Laravel框架表单验证详解
2014/09/04 PHP
YII框架行为behaviors用法示例
2019/04/26 PHP
javascript 跨浏览器开发经验总结(五) js 事件
2010/05/19 Javascript
JQuery 常用方法和事件详细介绍
2013/04/18 Javascript
js data日期初始化的5种方法
2013/12/29 Javascript
Node.js模块加载详解
2014/08/16 Javascript
jQuery仿360导航页图标拖动排序效果代码分享
2015/08/24 Javascript
全面了解JavaScript的数据类型转换
2016/07/01 Javascript
AngularJS入门教程之Scope(作用域)
2016/07/27 Javascript
JavaScript和jQuery获取input框的绝对位置实现方法
2016/10/13 Javascript
用Angular实时获取本地Localstorage数据,实现一个模拟后台数据登入的效果
2016/11/09 Javascript
xmlplus组件设计系列之文本框(TextBox)(3)
2017/05/03 Javascript
bootstrap multiselect下拉列表功能
2017/08/22 Javascript
Vue全家桶实践项目总结(推荐)
2017/11/04 Javascript
npm配置国内镜像资源+淘宝镜像的方法
2018/09/07 Javascript
angular4自定义组件非input元素实现ngModel双向数据绑定的方法
2018/12/28 Javascript
JavaScript设计模式之享元模式实例详解
2019/01/17 Javascript
JavaScript鼠标悬停事件用法解析
2020/05/15 Javascript
小程序实现多个选项卡切换
2020/06/19 Javascript
[06:45]DOTA2卡尔工作室 英雄介绍幻影长矛手篇
2013/07/12 DOTA
python 编程之twisted详解及简单实例
2017/01/28 Python
Python实现树莓派WiFi断线自动重连的实例代码
2017/03/16 Python
Python学习笔记之视频人脸检测识别实例教程
2019/03/06 Python
python实现维吉尼亚算法
2019/03/20 Python
python基于socket进行端口转发实现后门隐藏的示例
2019/07/25 Python
利用CSS3实现平移动画效果示例代码
2016/10/12 HTML / CSS
英国度假别墅预订:Sykes Cottages
2017/06/12 全球购物
重写子类方法时,抛出异常的书写注意事项
2015/10/17 面试题
花田少年史观后感
2015/06/16 职场文书
幼儿园科学课教学反思
2016/03/03 职场文书
写作指导:怎么书写竞聘演讲稿?
2019/07/04 职场文书
六年级作文之预言作文
2019/10/25 职场文书
Windows11里微软已经将驱动程序安装位置A盘删除
2021/11/21 数码科技
德生BCL3000抢先使用感受和评价
2022/04/07 无线电
SpringBoot详解自定义Stater的应用
2022/07/15 Java/Android