python如何實(shí)現(xiàn)表白神器-創(chuàng)新互聯(lián)

這篇文章主要介紹了python如何實(shí)現(xiàn)表白神器,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

創(chuàng)新互聯(lián)公司自成立以來,一直致力于為企業(yè)提供從網(wǎng)站策劃、網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、成都做網(wǎng)站、電子商務(wù)、網(wǎng)站推廣、網(wǎng)站優(yōu)化到為企業(yè)提供個(gè)性化軟件開發(fā)等基于互聯(lián)網(wǎng)的全面整合營銷服務(wù)。公司擁有豐富的網(wǎng)站建設(shè)和互聯(lián)網(wǎng)應(yīng)用系統(tǒng)開發(fā)管理經(jīng)驗(yàn)、成熟的應(yīng)用系統(tǒng)解決方案、優(yōu)秀的網(wǎng)站開發(fā)工程師團(tuán)隊(duì)及專業(yè)的網(wǎng)站設(shè)計(jì)師團(tuán)隊(duì)。

Python能夠干嘛?

可以做日常任務(wù),比如自動備份你的MP3;
可以做網(wǎng)站,很多著名的網(wǎng)站像知乎、YouTube就是Python寫的;
可以做網(wǎng)絡(luò)游戲的后臺,很多在線游戲的后臺都是Python開發(fā)的。

上面說的這些本人并沒有實(shí)現(xiàn)過;

但是我知道Python可以做一些有趣的東西,比如仿制抖音表白小軟件;

python如何實(shí)現(xiàn)表白神器

本人也是剛剛學(xué)習(xí)Python,這個(gè)腳本通過百度找到的,然后自己也重新寫了一遍,加深了映像,最主要的還是思路要清晰;

流程:

1、創(chuàng)建一個(gè)游戲屏幕
2、加載title
3、加載button,
4、當(dāng)鼠標(biāo)移動到 '算了吧' 上面的時(shí)候 重加加載桌面并隨機(jī)生成一個(gè) '算了吧' 坐標(biāo);
5、當(dāng)鼠標(biāo)移動到 ‘好呀'上面時(shí) 顯示不同的title

以下就是Python腳本:

import pygame
import random
 
 
# 設(shè)置游戲屏幕大小 這是一個(gè)常量
WIDTH, HEIGHT = 640, 480
 
screen = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32)
pygame.display.set_caption('FROM一個(gè)喜歡你很久的小哥哥')
 
# 標(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
 
# 點(diǎn)擊喜歡按鈕后顯示的頁面
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()

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“python如何實(shí)現(xiàn)表白神器”這篇文章對大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計(jì)公司,關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計(jì)公司行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、網(wǎng)站設(shè)計(jì)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

當(dāng)前題目:python如何實(shí)現(xiàn)表白神器-創(chuàng)新互聯(lián)
URL網(wǎng)址:http://muchs.cn/article36/djidpg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站云服務(wù)器、搜索引擎優(yōu)化、外貿(mào)建站、營銷型網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)