我已经使用python创建了一个exe。 pyinstaller --onefile --windowed --icon = icons \ icon.ico launcher.py 创建的exe文件将打开另一个电子exe文件。创建此python exe文件的原因是在os窗口中显示loading.gif,当电子exe版本在窗口中加载时,我使用kill命令关闭了该exe文件。现在有一个新的要求,我必须显示电子构建的百分比加载条,而不是显示此loading.gif。
现在,此逻辑背后的有趣部分是检查任务管理器中的进程加载状态,我已经获取了所有任务管理器进程。在该加载状态下,我必须计算python中电子建立的百分比。
我如何递归检查任务管理器进程的加载内存。谢谢
下面创建了一个显示loading.gif的exe
import json
import platform
import os, sys
from Tkinter import *
from subprocess import Popen, call
import wmi
c = wmi.WMI ()
root = Tk()
operating_system = platform.system().lower()
print operating_system
for process in c.Win32_Process ():
print process.ProcessId, process.Name
if operating_system == "darwin":
config_file_path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "../../../", "config"))
config = json.load(open(config_file_path))
loading_gif_path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "../../../", config['gif']))
cmd = config['open'][operating_system]
app_path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "../../../", cmd))
app_path = app_path.replace(" ", "\\ ")
call(['/bin/bash', "-c", 'open ' + app_path])
else:
config = json.load(open('config'))
loading_gif_path = config['gif']
cmd = config['open'][operating_system]
Popen(cmd)
frames = [PhotoImage(file=loading_gif_path, format = 'gif -index %i' %(i)) for i in range(config["frames"])]
def center(win):
win.update_idletasks()
width = config["width"]
height = config["height"]
x = (win.winfo_screenwidth() // 2) - (width // 2)
y = (win.winfo_screenheight() // 2) - (height // 2)
win.geometry('{}x{}+{}+{}'.format(width, height, x, y))
def update(ind):
frame = frames[ind]
if ind == (config["frames"] -1):
ind = 0
else:
ind += 1
label.configure(image=frame)
root.after(100, update, ind)
label = Label(root)
label.pack()
center(root)
root.after(0, update, 0)
if operating_system == "windows":
root.overrideredirect(1)
elif operating_system == "linux":
root.attributes('-type', 'splash')
else:
root.title("Educate")
root.overrideredirect(True)
root.wm_attributes("-topmost", True)
root.mainloop()