![]() |
Closing Threads and the chrome window it spawned from Tkinter close button - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Closing Threads and the chrome window it spawned from Tkinter close button (/thread-36000.html) |
Closing Threads and the chrome window it spawned from Tkinter close button - law - Jan-08-2022 from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager import time import threading from threading import * from tkinter import * def script1(): root = Tk() #Displays some widgets and Texts def on_closing(): #Looking for away to close all Threads at this point, also close the chrome window spawned by script2 root.destroy() root.protocol("WM_DELETE_WINDOW", on_closing) root.mainloop() def script2(): driver = webdriver.Chrome(ChromeDriverManager().install()) #driver.maximize_window() driver.get("https://google.com/") time.sleep(8) while True: #Do some web scrapping time.sleep(60) if __name__ == "__main__": # creating thread t1 = threading.Thread(target=script1, args=()) t2 = threading.Thread(target=script2, args=()) # starting thread 1 t1.start() # starting thread 2 t2.start() t1.join() t2.join()Hello Dev, I have the above code structure on which am trying to figure out a way of terminating/closing all the Threads by simply clicking the close button on the Tkinter Window. At the moment clicking the close button only terminates Thread1 while I want it to terminate both Threads.Kindly help me figure it out |