Python 入門指南 5.0

exercise4306.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
# 從 Brython 引入 document 並以 doc 為別名
from browser import document as doc
# 從 Brython 引入 window
from browser import window
# 從 browser 引入 timer
from browser import timer

# 計時秒數
t = 10

# 顯示計時器的事件
def animate_timer(event):
    doc["button"].style.display = "none"
    doc["display"].style.textAlign = "center"
    doc["display"].style.backgroundColor = "#222"
    doc["display"].style.color = "white"
    doc["display"].style.fontSize = "2.5em"
    def show_timer():
        global t
        doc["display"].text = f"{t}"
        t -= 1
        if t < 0:
            window.clearInterval(timer_id)
    timer_id = window.setInterval(show_timer, 1000)

# 按鈕註冊事件
doc["button"].bind("click", animate_timer)

# 檔名: exercise4306.py
# 說明:《Python入門指南》的練習
# 網站: http://kaiching.org
# 作者: 張凱慶
# 時間: 2023 年 12 月

回到練習題目
上一頁 exercise4305.py
回 Python 入門指南 5.0 首頁
下一頁 exercise4307.py
回 Python 教材首頁
回程式語言教材首頁