From 5b7128f743d75c744452c3e52e1c0be05e69c228 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sun, 27 Oct 2024 10:48:30 -0500 Subject: [PATCH] Fix window change title example exit Since the thread running the timer loop in `examples/window_title_change.py` is not a daemon thread, the program will not exit when the main thread ends due to the window closing. Instead of using an uninterruptible sleep, we can use the window closed event as the timer with the added bonus that we can exit the timer loop when the window is closed so that the program can exit. --- examples/window_title_change.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/window_title_change.py b/examples/window_title_change.py index 2222a1da..cd2182c3 100644 --- a/examples/window_title_change.py +++ b/examples/window_title_change.py @@ -1,14 +1,15 @@ """Change window title every three seconds.""" -import time - import webview def change_title(window): """changes title every 3 seconds""" for i in range(1, 100): - time.sleep(3) + # exit loop when window is closed + if window.events.closed.wait(3): + break + window.title = f'New Title #{i}' print(window.title)