当前位置:主页 > python教程 > python抖音表白程序源代码

使用python实现抖音表白

发布:2020-03-11 15:46:57 105


我们帮大家精选了Python相关的编程文章,网友宋访烟根据主题投稿了本篇教程内容,涉及到python、抖音表白程序、python抖音表白程序源代码相关内容,已被136网友关注,如果对知识点想更进一步了解可以在下方电子资料中获取。

python抖音表白程序源代码

本文实例为大家分享了python抖音表白程序的具体代码,供大家参考,具体内容如下

import sys
import random
import pygame
from pygame.locals import *
 
 
WIDTH, HEIGHT = 640, 480
BACKGROUND = (0, 191, 255)
 
 
# 按钮
def button(text, x, y, w, h, color, screen):
 pygame.draw.rect(screen, color, (x, y, w, h))
 font = pygame.font.Font('./font/simkai.ttf', 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 title(text, screen, scale, color=(255, 0, 0)):
 font = pygame.font.Font('./font/simkai.ttf', 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)
 
 
# 生成随机的位置坐标
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(BACKGROUND)
 font = pygame.font.Font('./font/simkai.ttf', 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 == QUIT:
  pygame.quit()
  sys.exit()
 
 
# 主函数
def main():
 pygame.init()
 screen = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32)
 pygame.display.set_caption('FROM一个喜欢你很久的小哥哥')
 clock = pygame.time.Clock()
 pygame.mixer.music.load('./bg_music/1.mp3')
 pygame.mixer.music.play(-1, 30.0)
 pygame.mixer.music.set_volume(0.25)
 unlike_pos_x = 330
 unlike_pos_y = 300
 unlike_pos_width = 100
 unlike_pos_height = 50
 like_pos_x = 180
 like_pos_y = 300
 like_pos_width = 100
 like_pos_height = 50
 running = True
 like_color = (255, 0, 255)
 while running:
 screen.fill(BACKGROUND)
 img = pygame.image.load("./imgs/1.png")
 imgRect = img.get_rect()
 imgRect.midtop = WIDTH//2, HEIGHT//4
 screen.blit(img, imgRect)
 for event in pygame.event.get():
  if event.type == pygame.MOUSEBUTTONDOWN:
  mouse_pos = pygame.mouse.get_pos()
  if mouse_pos[0] < like_pos_x+like_pos_width+5 and mouse_pos[0] > like_pos_x-5 and\
   mouse_pos[1] < like_pos_y+like_pos_height+5 and mouse_pos[1] > like_pos_y-5:
   like_color = BACKGROUND
   running = False
 mouse_pos = pygame.mouse.get_pos()
 if mouse_pos[0] < unlike_pos_x+unlike_pos_width+5 and mouse_pos[0] > unlike_pos_x-5 and\
  mouse_pos[1] < unlike_pos_y+unlike_pos_height+5 and mouse_pos[1] > unlike_pos_y-5:
  while True:
  unlike_pos_x, unlike_pos_y = get_random_pos()
  if mouse_pos[0] < unlike_pos_x+unlike_pos_width+5 and mouse_pos[0] > unlike_pos_x-5 and\
   mouse_pos[1] < unlike_pos_y+unlike_pos_height+5 and mouse_pos[1] > unlike_pos_y-5:
   continue
  break
 title('小姐姐,我观察你很久了', screen, scale=[2, 10])
 title('做我女朋友好不好呀', screen, scale=[2, 6])
 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, (255, 0, 255), screen)
 pygame.display.flip()
 pygame.display.update()
 clock.tick(60)
 show_like_interface('我就知道小姐姐你也喜欢我~', screen, color=(255, 0, 0))
 
 
if __name__ == '__main__':
 main()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持码农之家。


参考资料

相关文章

  • linux无法联网怎么下载python

    发布:2019-07-03

    在本篇文章里小编给大家整理的是关于linux无法联网怎么下载python的具体方法和实例代码,有需要的朋友们参考学习下。


  • python输入字符串的方法

    发布:2020-04-17

    字符串是python中最常用的数据类型,可以使用'或来创建字符串,如var='hello'。字符串支持通过索引来访问其中的值,同样也支持更新、替换、拼接、删除等操作。


  • python在手机上运行如何操作

    发布:2020-06-16

    python可以在手机上运行。QPython+就是一个Android设备上的脚本引擎,提供可在Android手机或平板电脑上运行的嵌入型Python解释器,控制台,编辑器,SL4A库。


  • python淘宝秒杀脚本编写实例

    发布:2020-06-16

    这篇文章主要为大家详细介绍了python实现淘宝秒杀脚本,扫码登录版,具有一定的参考价值,感兴趣的小伙伴们可以参考一下


  • Python实现批量导入1000条xlsx数据

    发布:2023-04-07

    本文主要介绍了Python实现批量导入1000条xlsx数据,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧


  • python+pycharm+django admin css样式问题解决方案

    python+pycharm+django admin css样式问题解决方案

    发布:2022-12-03

    给大家整理了关于python的教程,最近打算学习一下Python,基础知识有了大概的了解,想上手搞搞东西。我用的python 3.5+pycharm+django 1.11.2在使用Django,打开127.0.0.1:8000/admin时,发现admin模块css样式文件丢失,无法调用 按F12 发现


  • 怎么用python判断奇偶数

    怎么用python判断奇偶数

    发布:2022-06-29

    给网友们整理关于python的教程,要判断一个数为奇数还是偶数,依据的是它被2除后的余数。因此可以用“%”运算符来计算并判断。


  • 如何使用pickle存储Python的原生对象

    发布:2020-01-11

    下面小编就为大家带来一篇用pickle存储Python的原生对象方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧


网友讨论