Python 入門指南 5.0
exercise4304.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | # 從 Brython 引入 document 並以 doc 為別名 from browser import document as doc # 從 Brython 引入 window from browser import window # 從 datetime 引入 datetime from datetime import datetime # 顯示時間的事件 def animate_time(): doc["display"].style.textAlign = "center" doc["display"].style.backgroundColor = "#222" doc["display"].style.color = "white" doc["display"].style.fontSize = "2.5em" def show_time(): now = datetime.now() if now.hour < 10: hour = "0" + str(now.hour) else: hour = str(now.hour) if now.minute < 10: minute = "0" + str(now.minute) else: minute = str(now.minute) if now.second < 10: second = "0" + str(now.second) else: second = str(now.second) doc["display"].text = f"{hour}:{minute}:{second}" window.setInterval(show_time, 1000) # 進行時間動畫 animate_time() # 檔名: exercise4304.py # 說明:《Python入門指南》的練習 # 網站: http://kaiching.org # 作者: 張凱慶 # 時間: 2023 年 12 月 |