Tkinter 导入其他Python文件并运行它的Python GUI

Tkinter 导入其他Python文件并运行它的Python GUI,tkinter,python-3.6,file-import,Tkinter,Python 3.6,File Import,我尝试过在没有GUI的情况下导入并运行Formatting.py脚本,效果很好。但当我在GUI中这样做时,一旦我点击Run按钮,窗口就会进入(无响应)模式,甚至没有执行一行确认函数。 Formatting.py运行需要10分钟,但我认为执行不会因此停止 如果我从GUI代码中删除导入路径行。这段代码也很好用 我在这里错过了什么 class Cbuttons: def __init__(self): self.root = tk.Tk() self.root.title("Check

我尝试过在没有GUI的情况下导入并运行Formatting.py脚本,效果很好。但当我在GUI中这样做时,一旦我点击Run按钮,窗口就会进入(无响应)模式,甚至没有执行一行确认函数。 Formatting.py运行需要10分钟,但我认为执行不会因此停止

如果我从GUI代码中删除导入路径行。这段代码也很好用

我在这里错过了什么

class Cbuttons:
def __init__(self):
    self.root = tk.Tk()
    self.root.title("Checklist")
    self.CheckVar1 = tk.IntVar()
    self.CheckVar2 = tk.IntVar()
    self.CheckVar3 = tk.IntVar()
    self.CheckVar4 = tk.IntVar()
    self.label1_text = StringVar()
    self.label2_text = StringVar()
    self.label3_text = StringVar()
    self.label4_text = StringVar()
    self.B1 = Button()
    self.B2 = Button()
    self.L5 = Label()
    self.main()

def confirm(self):
    self.B1['state'] = 'disabled'
    self.B2['state'] = 'active'
    if self.CheckVar1.get():
        self.label1_text.set("Running File Formatting report. Start Time: "+ str(datetime.now()))
        # file_formatting_qad = import_path(r'Z:\Structured data\File_Formatting.py')
    if self.CheckVar2.get():
        self.label2_text.set("Running report 1")

    if self.CheckVar3.get():
        self.label3_text.set("Running report 2")

    if self.CheckVar4.get():
        self.label4_text.set("Running report 3")

    self.L5['text']='Reports Processed. It is now safe to close this Window!'


def main(self):
    C1 = tk.Checkbutton(self.root, text="File Formatting", variable=self.CheckVar1, anchor='w', onvalue=1,
                        offvalue=0, height=1, width=40)
    L1 = Label(self.root, textvariable=self.label1_text, state='disabled')

    C2 = tk.Checkbutton(self.root, text="Physicians Training Report", variable=self.CheckVar2, anchor='w', onvalue=1,
                        offvalue=0, height=1, width=40)
    L2 = Label(self.root, textvariable=self.label2_text, state='disabled')

    C3 = tk.Checkbutton(self.root, text="Initiated Cmplaints & Inquiries", variable=self.CheckVar3, anchor='w', onvalue=1,
                        offvalue=0, height=1, width=40)
    L3 = Label(self.root, textvariable=self.label3_text, state='disabled')

    C4 = tk.Checkbutton(self.root, text="Design Related Complaints", variable=self.CheckVar4, anchor='w', onvalue=1,
                        offvalue=0, height=1, width=40)
    L4 = Label(self.root, textvariable=self.label4_text,state='disabled')

    self.B1 = Button(self.root, text="RUN", command=self.confirm)
    self.B2 = Button(self.root, text="STOP", command=self.root.destroy,state = 'disabled')

    self.L5 = Label(self.root, text="Do not Hit 'STOP' Button or Close this Window untill this Text changes to Reports processed")



    C1.pack()
    C2.pack()
    C3.pack()
    C4.pack()
    L1.pack()
    L2.pack()
    L3.pack()
    L4.pack()
    self.B1.pack()
    self.B2.pack()
    self.L5.pack()
    self.root.mainloop()
如果name='main': Cbuttons()


如果运行需要10分钟,并且您正在UI线程上执行它,那么很有可能这就是您遇到问题的原因

我确实尝试过像上面那样执行线程和编辑代码,但仍然是一样的
thread = threading.Thread(target=import_path(r'Z:\Structured data\File_Formatting.py'), args=())
        thread.daemon = True  # Daemonize thread
        thread.start()