Python 入門指南 5.0

exercise4102.html

 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
39
40
41
42
43
44
<!DOCTYPE html>
<html>
<head>
    <!-- 設定網頁編碼 -->
    <meta charset="utf-8">
    <!-- 設定標題列文字 -->
    <title>Brython 練習</title>
    <!-- 引入 Brython 程式庫 -->
    <script src="https://cdn.jsdelivr.net/npm/brython@3/brython.min.js">
    </script>
    <script src="https://cdn.jsdelivr.net/npm/brython@3/brython_stdlib.js">
    </script>
    <!-- Python 程式 -->
    <script type="text/python">
# 從 Brython 引入 document 並以 doc 為別名
from browser import document as doc

# 輸入測試的事件
def key_test(event):
    doc["display"].text = f"{event.key}"

# 輸入文字框註冊事件
doc["input_text"].bind("keydown", key_test)
    </script>
</head>

<body id="body" onload="brython()">
    <h1>輸入測試</h1>
    
    <form>
        <p>
            <input type="text" id="input_text" value="" />
        </p>
        <p id="display">
        </p>
    </form>
</body>
</html>

<!-- 檔名: exercise4102.html
     說明:《Python入門指南》的範例程式
     網站: http://kaiching.org
     作者: 張凱慶
     時間: 2023 年 12 月  -->

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