Python MultiProcessing使tkinter GUI再次出现

问题描述

我正在学习创建GUI来开始多处理打印。 当我单击开始按钮时,它将再次绘制GUI。是否有限制它只能运行多处理打印的信息?

创建了gui.py:

def stopstart():
    global instance

    if startbtn['text']=="start":
            # Multiprocessing start here
            RunMultiProcessor()
            # End of Multiprocessing
            startbtn.configure(text="END")
            startbtn.configure(bg="#ff8a65") 
        else:
            popuptimer()
    else:
        startbtn.configure(text="start")
        startbtn.configure(bg="#e2f1f8")

startbtn = Button(leftframe,text = "start",background = "#e2f1f8",fg = "#000000",bd=1,command = stopstart)
startbtn.pack(side = TOP,expand = FALSE,fill = X)

创建了multiprocessing.py:

def run():
    print("printing")
    time.sleep(2)
    print("print end")

def RunMultiProcessor():
    for _ in range(2):
           processes[i] = multiprocessing.Process(target=run,))
                processes[i].start()

解决方法

感谢@Mark Tolonen的回答。下面是最终代码。

def stopstart():
    global instance

    if startbtn['text']=="start":
            # Multiprocessing start here
            RunMultiProcessor()
            # End of Multiprocessing
            startbtn.configure(text="END")
            startbtn.configure(bg="#ff8a65") 
        else:
            popuptimer()
    else:
        startbtn.configure(text="start")
        startbtn.configure(bg="#e2f1f8")

startbtn = Button(leftframe,text = "start",background = "#e2f1f8",fg = "#000000",bd=1,command = stopstart)
startbtn.pack(side = TOP,expand = FALSE,fill = X)

if __name__ == '__main__':
    top.mainloop()