python仿抖音表白神器
Python能夠干嘛?
可以做日常任務(wù),比如自動備份你的MP3;
可以做網(wǎng)站,很多著名的網(wǎng)站像知乎、YouTube就是Python寫的;
可以做網(wǎng)絡(luò)游戲的后臺,很多在線游戲的后臺都是Python開發(fā)的。
上面說的這些本人并沒有實現(xiàn)過;
但是我知道Python可以做一些有趣的東西,比如仿制抖音表白小軟件;

本人也是剛剛學(xué)習(xí)Python,這個腳本通過百度找到的,然后自己也重新寫了一遍,加深了映像,最主要的還是思路要清晰;
流程:
1、創(chuàng)建一個游戲屏幕
2、加載title
3、加載button,
4、當(dāng)鼠標(biāo)移動到 '算了吧' 上面的時候 重加加載桌面并隨機生成一個 '算了吧' 坐標(biāo);
5、當(dāng)鼠標(biāo)移動到 ‘好呀'上面時 顯示不同的title
以下就是Python腳本:
import pygame
import random
# 設(shè)置游戲屏幕大小 這是一個常量
WIDTH, HEIGHT = 640, 480
screen = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32)
pygame.display.set_caption('FROM一個喜歡你很久的小哥哥')
# 標(biāo)題
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)
# 初始化文字的坐標(biāo)
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)
# 生成隨機的位置坐標(biāo)
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)
# 獲取坐標(biāo)
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()
大家有好的創(chuàng)意也可以一起交流下;
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 教你利用Python+Turtle繪制簡易版愛心表白
- Python繪制的愛心樹與表白代碼(完整代碼)
- python實現(xiàn)跨年表白神器--你值得擁有
- 一篇文章教你用python畫動態(tài)愛心表白
- python如何寫出表白程序
- 520使用Python實現(xiàn)“我愛你”表白
- 程序員的七夕用30行代碼讓Python化身表白神器
- 很酷的python表白工具 你喜歡我嗎
- python3實現(xiàn)表白神器
- python抖音表白程序源代碼
- 我喜歡你 抖音表白程序python版
- python七夕浪漫表白源碼
- python浪漫表白源碼
- python愛心表白 每天都是浪漫七夕!
- 520必備!這些Python表白代碼祝你脫單成功
相關(guān)文章
使用Python操作Elasticsearch數(shù)據(jù)索引的教程
這篇文章主要介紹了使用Python操作Elasticsearch數(shù)據(jù)索引的教程,Elasticsearch處理數(shù)據(jù)索引非常高效,要的朋友可以參考下2015-04-04
python繪制規(guī)則網(wǎng)絡(luò)圖形實例
今天小編大家分享一篇python繪制規(guī)則網(wǎng)絡(luò)圖形實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-12-12

