Skip to content

Commit

Permalink
Fix window change title example exit
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dlech committed Oct 27, 2024
1 parent ba0880c commit 5b7128f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions examples/window_title_change.py
Original file line number Diff line number Diff line change
@@ -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)

Expand Down

0 comments on commit 5b7128f

Please sign in to comment.