python-3.x - 如何在 Python 中运行代码之前添加延迟
问题描述
我只是想知道如何在运行代码之前添加延迟,例如:我制作了一个程序,但想要添加 5 秒延迟,因此用户必须在程序启动前等待 5 秒:
import time
import pygame
import sys
import os
pygame.init()
screen = pygame.display.set_mode((250,150))
pygame.display.set_caption('Message from Admin')
font = pygame.font.SysFont("Lucida Console", 30)
label = font.render("You moron", 1, (1, 1, 1))#JUST TO TROLL
while True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
time.sleep(0.10)
screen = pygame.display.set_mode((250,150))
pygame.display.set_caption('Error')
screen.fill((255,255,255))
screen.blit(label, (50,50))
pygame.display.update()
解决方案
推荐阅读
- imodeljs - 我可以使用自己的服务来构建 imodel 显示程序吗?
- java - 如何访问嵌套 hashmap 的关键内容
- phpexcel - 使用phpspreadsheet获取excel单元格内容的下划线
- c# - 类中字段的属性
- memory-management - Valgrind 安装失败 MacOS Mojave
- c# - 平等和多态
- php - 在 Codeigniter 中将多行插入数据库
- jinja2 - Homeassistant 中的 jinja2 模板语法
- php - PHP cURL 在服务器上验证 Facebook API 登录 access_token?
- c# - 我想在我的 datagridview 标题中增加日期