Python Forum
Closing Threads and the chrome window it spawned from Tkinter close button
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Closing Threads and the chrome window it spawned from Tkinter close button
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to edit Tkinter Minimize, Maximize, and Close Buttons kucingkembar 7 445 Apr-26-2024, 11:36 AM
Last Post: kucingkembar
  add entries and labels to the window tkinter jacksfrustration 3 701 Oct-10-2023, 06:41 PM
Last Post: buran
  Is there a way to call and focus any popup window outside of the main window app? Valjean 6 1,985 Oct-02-2023, 04:11 PM
Last Post: deanhystad
  how to open a popup window in tkinter with entry,label and button lunacy90 1 971 Sep-01-2023, 12:07 AM
Last Post: lunacy90
  Tkinter button images not showing up lunacy90 7 1,733 Aug-31-2023, 06:39 PM
Last Post: deanhystad
Bug tkinter.TclError: bad window path name "!button" V1ber 2 873 Aug-14-2023, 02:46 PM
Last Post: V1ber
  Pyspark Window: perform sum over a window with specific conditions Shena76 0 1,219 Jun-13-2022, 08:59 AM
Last Post: Shena76
Sad Selenium: can't open a new window after clicking a button and I don't know why noahverner1995 0 2,019 Jan-22-2022, 09:55 AM
Last Post: noahverner1995
  tkinter auto press button kucingkembar 2 3,277 Dec-24-2021, 01:23 PM
Last Post: kucingkembar
  Need to run 100+ Chrome’s with Selenium but can’t get past ~15 without breaking imillz 0 1,407 Sep-04-2021, 04:51 PM
Last Post: imillz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020