一:使用pyinstaller打包成exe执行文件进行运行。在调试过程中,发现当gui界面的窗口关闭后,后台程序还在运行,并没有终止程序。
二:解决方法
让每一个子线程在开启之前设置一个守护线程,这样就可以在主线程结束之后,同时也能停止子线程。
Button(myWindow, text='Apply', command=self.download_customers).place()
def download_customers(self):
thread = threading.Thread(target=self.download)
thread.setDaemon(True) # 设置线程为守护线程,防止退出主线程时,子线程仍在运行
thread.start()