为什么tkinter下运行多进程就会弹出多个窗口?
为什么tkinter下运行多进程就会弹出多个窗口?谢谢!!
import multiprocessing as mp
import tkinter as tk
def job(q):
res = 0
for i in range(1000000):
res += i + i**2 + i**3
q.put(res) # queue
def doit():
q = mp.Queue()
p1 = mp.Process(target=job, args=(q,))
p2 = mp.Process(target=job, args=(q,))
p1.start()
p2.start()
p1.join()
p2.join()
res1 = q.get()
res2 = q.get()
print('multicore:',res1 + res2)
root = tk.Tk()
frame = tk.Frame(root,height=400,width=400)
frame.grid(row=0)
theButton = tk.Button(frame,height=4,width=10,text='执行',command=doit)
theButton.grid(row=1,column=0)
root.mainloop() import multiprocessing as mp
import tkinter as tk
def job(q):
res = 0
for i in range(1000000):
res += i + i**2 + i**3
q.put(res) # queue
def doit():
q1 = mp.Queue()
q2 = mp.Queue()
p1 = mp.Process(target=job, args=(q1,))
p2 = mp.Process(target=job, args=(q2,))
p1.start()
p2.start()
p1.join()
p2.join()
res1 = q1.get()
res2 = q2.get()
print('multicore:',res1 + res2)
if __name__ == '__main__':
root = tk.Tk()
frame = tk.Frame(root,height=400,width=400)
frame.grid(row=0)
theButton = tk.Button(frame,height=4,width=10,text='执行',command=doit)
theButton.grid(row=1,column=0)
root.mainloop()
逃兵 发表于 2021-3-26 11:01
谢谢,请问为什么加上if__name__就可以了? https://docs.python.org/zh-tw/3.6/library/multiprocessing.html#multiprocessing-programming 逃兵 发表于 2021-3-26 11:38
https://docs.python.org/zh-tw/3.6/library/multiprocessing.html#multiprocessing-programming
谢谢,如果可以话,帮我看一下另一个帖子的问题,谢谢
页:
[1]