欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python仿抖音表白神器

 更新時間:2019年04月08日 08:37:03   作者:weixin_33704234  
這篇文章主要教大家制作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)移動到 '算了吧' 上面的時候 重加加載桌面并隨機(jī)生成一個 '算了吧' 坐標(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)
 
# 生成隨機(jī)的位置坐標(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í)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 序列化Python對象的方法

    序列化Python對象的方法

    這篇文章主要介紹了序列化Python對象的方法,文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-08-08
  • python飛機(jī)大戰(zhàn)游戲?qū)嵗v解

    python飛機(jī)大戰(zhàn)游戲?qū)嵗v解

    在本篇文章里小編給大家整理的是一篇關(guān)于python飛機(jī)大戰(zhàn)游戲?qū)嵗v解,有興趣的朋友們可以參考下。
    2020-12-12
  • 使用Python操作Elasticsearch數(shù)據(jù)索引的教程

    使用Python操作Elasticsearch數(shù)據(jù)索引的教程

    這篇文章主要介紹了使用Python操作Elasticsearch數(shù)據(jù)索引的教程,Elasticsearch處理數(shù)據(jù)索引非常高效,要的朋友可以參考下
    2015-04-04
  • 分享unittest單元測試框架中幾種常用的用例加載方法

    分享unittest單元測試框架中幾種常用的用例加載方法

    這篇文章主要介紹了unittest單元測試框架中常用的幾種用例加載方法,幫助大家更好的理解和使用python的unittest測試模塊,感興趣的朋友可以了解下
    2020-12-12
  • python PyQt5 爬蟲實現(xiàn)代碼

    python PyQt5 爬蟲實現(xiàn)代碼

    這篇文章主要介紹了python PyQt5 爬蟲實現(xiàn)代碼,代碼簡單易懂,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-04-04
  • 在k8s上部署pytorch分布式程序的完整步驟記錄

    在k8s上部署pytorch分布式程序的完整步驟記錄

    Kubernetes的核心優(yōu)勢在于其能夠提供一個可擴(kuò)展、靈活且高度可配置的平臺,使得應(yīng)用程序的部署、擴(kuò)展和管理變得前所未有的簡單下面這篇文章主要給大家介紹了關(guān)于在k8s上部署pytorch分布式程序的完整步驟,需要的朋友可以參考下
    2024-08-08
  • python繪制規(guī)則網(wǎng)絡(luò)圖形實例

    python繪制規(guī)則網(wǎng)絡(luò)圖形實例

    今天小編大家分享一篇python繪制規(guī)則網(wǎng)絡(luò)圖形實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • Python爬取視頻時長場景實踐示例

    Python爬取視頻時長場景實踐示例

    這篇文章主要為大家介紹了Python獲取視頻時長場景實踐示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-07-07
  • Python編程之序列操作實例詳解

    Python編程之序列操作實例詳解

    這篇文章主要介紹了Python編程之序列操作,結(jié)合實例形式分析了Python序列的功能、相關(guān)函數(shù)與具體使用技巧,需要的朋友可以參考下
    2017-07-07
  • Python 使用matplotlib模塊模擬擲骰子

    Python 使用matplotlib模塊模擬擲骰子

    這篇文章主要介紹了Python 使用matplotlib模塊模擬擲骰子,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-08-08

最新評論