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
  Tkinter: Problem with storing data from one window to the other iforire 1 955 May-11-2025, 01:31 PM
Last Post: deanhystad
  Unique Tkinter Window kucingkembar 11 3,839 Aug-11-2024, 01:49 PM
Last Post: deanhystad
  How to edit Tkinter Minimize, Maximize, and Close Buttons kucingkembar 7 11,563 Apr-26-2024, 11:36 AM
Last Post: kucingkembar
  add entries and labels to the window tkinter jacksfrustration 3 3,293 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 7,727 Oct-02-2023, 04:11 PM
Last Post: deanhystad
  how to open a popup window in tkinter with entry,label and button lunacy90 1 4,562 Sep-01-2023, 12:07 AM
Last Post: lunacy90
  Tkinter button images not showing up lunacy90 7 5,678 Aug-31-2023, 06:39 PM
Last Post: deanhystad
Bug tkinter.TclError: bad window path name "!button" V1ber 2 3,166 Aug-14-2023, 02:46 PM
Last Post: V1ber
  Pyspark Window: perform sum over a window with specific conditions Shena76 0 2,547 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 3,142 Jan-22-2022, 09:55 AM
Last Post: noahverner1995

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.