Python:在不暂停脚本的情况下显示消息框(tkinter)

时间:2019-01-09 22:55:44

标签: python tkinter messagebox

使用messagebox.showwarning命令时,只有按下OK按钮,它才会执行下几行。

有没有一种方法可以使我的脚本继续运行而无需按OK(确定)按钮?

就像在此示例中一样...我一直在努力开发一个有趣的程序。 如果它检测到进程,则将其关闭,然后弹出msgbox...。但是,如果您不单击“确定”按钮,则可以重新打开该进程,并且由于未单击“确定”按钮,所以程序中不会发生任何事情。 / p>

  #!python
# coding: utf-8
import time
import pygame
import sys
import os
import random
import time
import random
import pyautogui
import subprocess
from time import sleep
import psutil
import tkinter
from tkinter import messagebox
import threading
from threading import Thread
import ctypes, sys

PROCNAME = 'something.exe'

os.environ['SDL_VIDEO_WINDOW_POS'] = str(random.randrange(1,1000)) + "," + str(random.randrange(1,1000))
pygame.init()
exdy = 666
#mouse
def move_mouse(how_long_in_seconds):
    start_time = time.time()
    time_elapsed = time.time() - start_time
    xsize, ysize = pyautogui.size()

    while time_elapsed < how_long_in_seconds:
        x, y = random.randrange(xsize), random.randrange(ysize)
        pyautogui.moveTo(x, y, duration=0.1)
        time_elapsed = time.time() - start_time
#mouse end   
i = 1

screen = pygame.display.set_mode((300,150))
pygame.display.set_caption('Message from Admin')
font = pygame.font.SysFont("Lucida Console", 20)
label = font.render("Jdi do prdele ;)", 1, (0,0,0))
def hhaf():
    move_mouse(120)


si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
root = tkinter.Tk()
root.withdraw()


def is_admin():
    try:
        return ctypes.windll.shell32.IsUserAnAdmin()
    except:
        return False

if is_admin():
    while True:
        for proc in psutil.process_iter():
            if proc.name() == PROCNAME:
                os.system('taskkill /T /F /IM someting.exe')           
                messagebox.showwarning("ADMIN", "Do not!")

                i += 1
            elif i == 3:
                    messagebox.showerror("ONE ANGRY BOI", "I am done with you")
                    messagebox.showinfo("ONE ANGRY BOI", "closing everything")
                    os.system("taskkill /T /F /IM something.exe")



            else:

                for event in pygame.event.get():
                    if event.type==pygame.QUIT:
                        move_mouse(0.1)
                        os.environ['SDL_VIDEO_WINDOW_POS'] = str(random.randrange(1,700)) + "," + str(random.randrange(1,700))
                        pygame.quit()
                        time.sleep(0.10)
                        print(i)



                screen = pygame.display.set_mode((300,150))
                pygame.display.set_caption('Message from Admin')                
                screen.fill((255,255,255))
                screen.blit(label, (50,50))
                pygame.display.update()
else:
    ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)

0 个答案:

没有答案