Son aktivite 9 months ago

此程式透過 threading.Timer 延遲指定秒數後,自動開啟指定的 URL。適用於自動化測試、提醒功能或延遲啟動特定網頁,確保主程式不中斷的情況下執行非同步操作。

Revizyon c52daf581708ea9817bf783a1b6071dabcb61222

delayed_web_open.py Ham
1import threading
2import webbrowser
3
4def open_url(url):
5 """ 開啟指定的 URL """
6 webbrowser.open(url, new=2)
7
8# 設定延遲時間(秒)
9delay = 2
10url = "https://www.example.com"
11
12# 在 delay 秒後執行 open_url 函式
13threading.Timer(delay, lambda: open_url(url)).start()
14
15print(f"將在 {delay} 秒後開啟:{url}")
16