【发布时间】:2020-08-31 06:38:03
【问题描述】:
我正在尝试在代码执行计算时在寡妇中播放加载 gif。
我读过这篇文章:Updating Popup.Animated to play gif until external task is completed (PYSimpleGUI)
但这不适用于我的情况,因为我没有尝试使用sg.PopupAnimated。
我想要做的是通过动画 gif 来更新显示的寡妇,直到代码结束并关闭窗口。
我确定它与循环有关,但我不知道是什么。
这是我的代码:
layout4 = [[sg.Image(r'C:\Users\...\Pictures\img.png'), sg.Text('Please wait')],
[sg.Image(r'C:\Users\...\Pictures\animation.gif', size = (120,120), key = "Prog_bar")]]
window4 = sg.Window("HAL 220").Layout(layout4)
event, values = window4.Read()
while True:
window4.FindElement("Prog_bar").UpdateAnimation("animation.gif",time_between_frames=100)
if event is None :
break
# ===== That would be the section of the code with the function and the loop =====
def main(alpha, alg_type):
""" Set the variables for the loop """
futures = []
e = ProcessPoolExecutor(8) # Processes is almost 8 times faster in this cases than ThreadPoolExecutor
if alg_type == "O":
F = FFR_ME
elif alg_type == "NO":
F = FFR_ME_NO
else :
raise TypeError("Algortithm type selected does not exist. Must be 'O' or 'NO'")
""" Loop over the different task summarized in the tab 'N_tab' during the MPO_PROC step. """
for task in N_tab["TASK_NUMBER"]:
""" Declare variables N, n , f based on the previous calculations """
N = int(N_tab.loc[N_tab["TASK_NUMBER"] == task, "N_Task"])
n = int(N_tab.loc[N_tab["TASK_NUMBER"] == task, "n_i"])
f = int(N_tab.loc[N_tab["TASK_NUMBER"] == task, "F"])
"""" Implement the function using the concurrent.future module for multiprocessing. """
future = e.submit(F, N, n, f, alpha)
futures.append(future)
results = [ff.result() for ff in futures]
for i in range(len(results)):
f = int(N_tab.loc[i, "F"])
N_tab.loc[i,"LBound"] = results[i][0][f]
N_tab.loc[i,"UBound"] = results[i][1][f]
N_tab.loc[i,"ME"] = (N_tab.loc[i,"UBound"] - N_tab.loc[i,"LBound"])/\
(2*N_tab.loc[i,"N_Task"])
N_tab.loc[i,"FFR"] = (N_tab.loc[i,"LBound"] + (N_tab.loc[i,"UBound"] - N_tab.loc[i,"LBound"])/2)/\
N_tab.loc[i,"N_Task"]
if __name__ == "__main__":
main(alpha, alg_type)
# ====== End of the section end of the calculation
window4.close()
谢谢
【问题讨论】:
标签: python animation popup gif pysimplegui