Python 入門指南 5.0
exercise4309.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125 | # 從 Brython 引入 document 並以 doc 為別名
from browser import document as doc
# 暫存輸入
command = ""
# 進行按鈕 1
def method_1(event):
global command
command += "1"
doc["display"].text = command
# 進行按鈕 2
def method_2(event):
global command
command += "2"
doc["display"].text = command
# 進行按鈕 3
def method_3(event):
global command
command += "3"
doc["display"].text = command
# 進行按鈕 4
def method_4(event):
global command
command += "4"
doc["display"].text = command
# 進行按鈕 5
def method_5(event):
global command
command += "5"
doc["display"].text = command
# 進行按鈕 6
def method_6(event):
global command
command += "6"
doc["display"].text = command
# 進行按鈕 7
def method_7(event):
global command
command += "7"
doc["display"].text = command
# 進行按鈕 8
def method_8(event):
global command
command += "8"
doc["display"].text = command
# 進行按鈕 9
def method_9(event):
global command
command += "9"
doc["display"].text = command
# 進行按鈕 0
def method_0(event):
global command
command += "0"
doc["display"].text = command
# 進行按鈕 .
def method_dot(event):
global command
command += "."
doc["display"].text = command
# 進行按鈕 +
def method_add(event):
global command
command += "+"
doc["display"].text = command
# 進行按鈕 -
def method_mimus(event):
global command
command += "-"
doc["display"].text = command
# 進行按鈕 *
def method_multiply(event):
global command
command += "*"
doc["display"].text = command
# 進行按鈕 /
def method_divide(event):
global command
command += "/"
doc["display"].text = command
# 進行按鈕 =
def method_equal(event):
global command
command = str(eval(command))
doc["display"].text = command
# 按鈕註冊事件
doc["button1"].bind("click", method_1)
doc["button2"].bind("click", method_2)
doc["button3"].bind("click", method_3)
doc["button4"].bind("click", method_4)
doc["button5"].bind("click", method_5)
doc["button6"].bind("click", method_6)
doc["button7"].bind("click", method_7)
doc["button8"].bind("click", method_8)
doc["button9"].bind("click", method_9)
doc["button0"].bind("click", method_0)
doc["button_dot"].bind("click", method_dot)
doc["button_add"].bind("click", method_add)
doc["button_minus"].bind("click", method_mimus)
doc["button_multiply"].bind("click", method_multiply)
doc["button_divide"].bind("click", method_divide)
doc["button_equal"].bind("click", method_equal)
# 檔名: exercise4309.py
# 說明:《Python入門指南》的練習
# 網站: http://kaiching.org
# 作者: 張凱慶
# 時間: 2023 年 12 月
|