-1

We're doing a "virus" now and I was told to make a delay in my code. Help me, please. Here's the code:

import pygame         
from tkinter import *
from tkinter import messagebox 
import time               
import random
pygame.init()
screen = pygame.display.set_mode((800, 300))
pygame.display.set_caption("ЗАРАЖЕНИЕ АЧЕ)")

Tk().wm_withdraw()
font = pygame.font.SysFont("Lucida Console", 35)
label2 = font.render("DELETING ALL PASSWORDS. . . . .", 1, (12, 140, 0, 1))

a = 0

while True:
    screen.fill((0, 0, 0))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            time.sleep(0.5)
            screen = pygame.display.set_mode((800, 300))
            pygame.display.set_caption("ЗАРАЖЕНИЕ АЧЕ)")
            messagebox.showerror("ERROR!", " Вы попытались закрыть окно! Начинаю удаление файлов")
    warning = f"Процент удаления: {a}"
    label3 = font.render(warning, 1, (12, 140, 0, 1))
    a = a + 1
    time.sleep(0.1)
    if a >= 100:
        break

    screen.blit(label2, (50, 50))
    screen.blit(label3, (50, 100))
    pygame.display.update()

My question is, I don't know which command to use to delay and where to put it.

Thank you in advance!

Andriy
  • 35
  • 5
  • 2
    Please give textual information and code as text, not as link to picture of text. https://meta.stackoverflow.com/a/285557/7733418 That is part of providing a helpful [mre]. – Yunnosch May 30 '20 at 10:09
  • what should be delayed? – bb1950328 May 30 '20 at 10:31
  • @Sadap warning = f"Процент удаления: {a}" label3 = font.render(warning, 1, (12, 140, 0, 1)) a = a + 1 time.sleep(0.1) if a >= 100: break – Andriy May 30 '20 at 10:34
  • @Andrew then place `time.sleep(2)` before that line. `2` is the number of seconds to wait – bb1950328 May 30 '20 at 10:37

1 Answers1

3

With pygame, you don't use time.sleep, you need to replace your time.sleep code with pygame.time.wait, which is written in milliseconds, so your updated code would look like so:

import pygame         
from tkinter import *
from tkinter import messagebox 
import time               
import random
pygame.init()
screen = pygame.display.set_mode((800, 300))
pygame.display.set_caption("ЗАРАЖЕНИЕ АЧЕ)")

Tk().wm_withdraw()
font = pygame.font.SysFont("Lucida Console", 35)
label2 = font.render("DELETING ALL PASSWORDS. . . . .", 1, (12, 140, 0, 1))

a = 0

while True:
    screen.fill((0, 0, 0))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.display.quit()
            pygame.time.wait(500)
            screen = pygame.display.set_mode((800, 300))
            pygame.display.set_caption("ЗАРАЖЕНИЕ АЧЕ)")
            messagebox.showerror("ERROR!", " Вы попытались закрыть окно! Начинаю удаление файлов")
    warning = f"Процент удаления: {a}"
    label3 = font.render(warning, 1, (12, 140, 0, 1))
    a = a + 1
    pygame.time.wait(100)
    if a >= 100:
        break

    screen.blit(label2, (50, 50))
    screen.blit(label3, (50, 100))
    pygame.display.update()

Also with your code I replaced pygame.quit() with pygame.display.quit() so the code will continue after the so called "error".

jimbob88
  • 697
  • 5
  • 20