用python做一个表白视频(python仿抖音表白神器)
类别:脚本大全 浏览量:2482
时间:2021-10-27 10:04:05 用python做一个表白视频
python仿抖音表白神器python能够干嘛?
可以做日常任务,比如自动备份你的mp3;
可以做网站,很多著名的网站像知乎、youtube就是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.jpg" alt="用python做一个表白视频(python仿抖音表白神器)" border="0" /> 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() |
大家有好的创意也可以一起交流下;
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持开心学习网。
原文链接:https://blog.csdn.net/weixin_33704234/article/details/86837635
您可能感兴趣
- eclipse配置python(eclipse创建python项目步骤详解)
- python语句for循环(Python基础之循环语句用法示例for、while循环)
- python中startswith使用教程(Python os.access用法实例)
- python 怎么解析中文(Python中一般处理中文的几种方法)
- python渗透攻击(Python实现DDos攻击实例详解)
- pycharm怎么创建django项目(Python、 Pycharm、Django安装详细教程图文)
- python一组数字求和(Python3数字求和的实例)
- python找出数组的最大值(Python查找数组中数值和下标相等的元素示例二分查找)
- python正则表达式处理教学(使用Python正则表达式操作文本数据的方法)
- python在mysql创建数据库(python3对接mysql数据库实例详解)
- python发送微信消息脚本(python实现给微信指定好友定时发送消息)
- python使用pandas数据分析系列(python使用pandas处理大数据节省内存技巧推荐)
- python元组操作方法(Python元组常见操作示例)
- python中如何遍历键(Python中按值来获取指定的键)
- python数据类型基本知识入门(Python Pexpect库的简单使用方法)
- python中mod函数的使用方法(详解Python3中ceil函数用法)
- 今天要吃什么(今天要吃什么菜)
- 三杨之一 南杨 杨溥 安贞履节,酿醴调羹,宰相之气(三杨之一南杨杨溥)
- 今天会下雨吗(今天会下雨吗小说)
- 追连续剧,品古今联4 明代三杨,联妙诗佳(追连续剧品古今联4)
- 三杨 共辅四朝帝王,构建明帝国内阁行政圈(三杨共辅四朝帝王)
- 红色文化进国企(红色文化进国企)
热门推荐
- js tab栏案例(JavaScript实现Tab栏切换特效)
- opencv 图像匹配python(OpenCV+Python识别车牌和字符分割的实现)
- dedecms手册教程(dedecms标签大全非常经典)
- mysql8.0.12安装教程图解(mysql 8.0.22 zip压缩包版免安装下载、安装配置步骤详解)
- uni app 小程序全局样式没法用(uniapp封装小程序雷达图组件的完整代码)
- 如何选择适合自己的云服务器(云服务器操作系统如何选择)
- pythondocx安装教程(Python docx库用法示例分析)
- 云ip内网虚拟机使用(新网云主机如何使用密钥进行登陆)
- iis服务器无法启动(Windows服务器中IIS返回的网页错误代码大汇总及原因解)
- python 基于内容的推荐系统(不到40行代码用Python实现一个简单的推荐系统)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9