python tkinter加入多线程是报错:main thread is not in main loop,位置是在fp = e1.get的位置,请教下需要怎么改

from ntpath import join
import queue
import tkinter as tk
import time
import subprocess
import re
import threading
from queue import Queue
import os

win = tk.Tk()
win.title("xxxx")
win.geometry("388x300")


tk.Label(win,text='文件路径:',font=('Arial', 10)).grid(row=6,column=0,sticky='E')
e1 = tk.Entry(win)
e1.grid(row=6,column=1,sticky='W')
t1 = tk.Text(win,width=55, height=17)
t1.grid(row=13,column=0,rowspan=8,columnspan=3,padx=0,pady=10)

z,c,d = [],[],[]


def printtext():
    t1.insert(1.0,filepath())

def filepath():
    fp = e1.get()
    f = open('{fp}')     
    for ip in f.readlines():
        ips = ip
        name = re.findall('[\u4e00-\u9fa5]+',ips)
        ip = re.findall('\d+\.\d+\.\d+\.\d+',ips)  
        ip = ''.join(ip) 
        #print(ip)
        res = subprocess.call('ping -n 2 -w 5 %s' % ip,stdout=subprocess.PIPE)
        print(ip,res)
        if res == 0 :   
            z.append(ip)
        else:
            c.append(ips) 
    
    sum = '{:.2f}'.format(len(c)/(len(z)+len(c)))
    he = len(z)+len(c)
    diao = len(c)
    np = [i for i in c]
    nameip = ''.join(np)
    return f'测试地址总数:{he}\n丢包率:{sum}%\n掉线地址:{diao}\n掉线名称及地址:\n{nameip}'         
    
xiancheng = 50        
threads = []
for xian in range(xiancheng):
        thread = threading.Thread(target=filepath)
        thread.start()
        threads.append(thread)

for thread in threads:
        thread.join()

b1 = tk.Button(win,text='提交',font=('Arial',10),bg='red',width=8, height=1,command=filepath).grid(row=22,column=2,sticky='W')
t1.window_create( "insert",window=b1)


win.mainloop()





看看有没有帮助