回答編集履歴
3
数字キーにイベント引数が必要なので関数呼び出しを元に戻す
test
CHANGED
@@ -69,8 +69,9 @@
|
|
69
69
|
|
70
70
|
# create buttons
|
71
71
|
for row, col, text, func, bg in button_layout:
|
72
|
-
button = tk.Button(self, text=text, font=font[bg], bg=bg, fg=fg[bg]
|
72
|
+
button = tk.Button(self, text=text, font=font[bg], bg=bg, fg=fg[bg])
|
73
73
|
button.grid(column=col, row=row, sticky=(tk.N + tk.S + tk.E + tk.W))
|
74
|
+
button.bind('<Button-1>', func)
|
74
75
|
|
75
76
|
# create entry
|
76
77
|
self.numbox = tk.Entry(self, background=BLACK, foreground=WHITE, font=('MSゴシック', 30), justify=tk.RIGHT)
|
@@ -83,26 +84,26 @@
|
|
83
84
|
self.rowconfigure(i, weight=1)
|
84
85
|
|
85
86
|
# functions
|
86
|
-
def numinput(self): pass
|
87
|
+
def numinput(self, e): pass
|
87
|
-
def add(self): pass
|
88
|
+
def add(self, e): pass
|
88
|
-
def sub(self): pass
|
89
|
+
def sub(self, e): pass
|
89
|
-
def mul(self): pass
|
90
|
+
def mul(self, e): pass
|
90
|
-
def div(self): pass
|
91
|
+
def div(self, e): pass
|
91
|
-
def equal(self): pass
|
92
|
+
def equal(self, e): pass
|
92
|
-
def clear(self): pass
|
93
|
+
def clear(self, e): pass
|
93
|
-
def point(self): pass
|
94
|
+
def point(self, e): pass
|
94
|
-
def MC(self): pass
|
95
|
+
def MC(self, e): pass
|
95
|
-
def MR(self): pass
|
96
|
+
def MR(self, e): pass
|
96
|
-
def MS(self): pass
|
97
|
+
def MS(self, e): pass
|
97
|
-
def M_plus(self): pass
|
98
|
+
def M_plus(self, e): pass
|
98
|
-
def M_sub(self): pass
|
99
|
+
def M_sub(self, e): pass
|
99
|
-
def in_tax(self): pass
|
100
|
+
def in_tax(self, e): pass
|
100
|
-
def out_tax(self): pass
|
101
|
+
def out_tax(self, e): pass
|
101
|
-
def root(self): pass
|
102
|
+
def root(self, e): pass
|
102
|
-
def plu_sub(self): pass
|
103
|
+
def plu_sub(self, e): pass
|
103
|
-
def CE(self): pass
|
104
|
+
def CE(self, e): pass
|
104
|
-
def percent(self): pass
|
105
|
+
def percent(self, e): pass
|
105
|
-
def fact(self): pass
|
106
|
+
def fact(self, e): pass
|
106
107
|
|
107
108
|
|
108
109
|
def main():
|
2
処理簡略化
test
CHANGED
@@ -10,6 +10,7 @@
|
|
10
10
|
SMOKE_WHITE = ('#a5a5a5')
|
11
11
|
WHITE = ('#ffffff')
|
12
12
|
BLACK = ('#000000')
|
13
|
+
|
13
14
|
|
14
15
|
class Calclator(tk.Frame):
|
15
16
|
|
@@ -53,19 +54,23 @@
|
|
53
54
|
(5, 4, '.', self.point, LIGHT_GRAY),
|
54
55
|
(5, 5, '=', self.equal, ORANGE)
|
55
56
|
)
|
57
|
+
font = {
|
58
|
+
DARK_GRAY: ('MSゴシック', 15),
|
59
|
+
LIGHT_GRAY: ('MSゴシック', 20),
|
60
|
+
SMOKE_WHITE: ('MSゴシック', 15),
|
61
|
+
ORANGE: ('MSゴシック', 20),
|
62
|
+
}
|
63
|
+
fg = {
|
64
|
+
DARK_GRAY: WHITE,
|
65
|
+
LIGHT_GRAY: WHITE,
|
66
|
+
SMOKE_WHITE: BLACK,
|
67
|
+
ORANGE: WHITE,
|
68
|
+
}
|
56
69
|
|
57
70
|
# create buttons
|
58
|
-
for row, col,
|
71
|
+
for row, col, text, func, bg in button_layout:
|
59
|
-
if color == DARK_GRAY:
|
60
|
-
button = tk.Button(self, text=label, font=('MSゴシック', 15), bg=DARK_GRAY, foreground=WHITE)
|
61
|
-
elif color == LIGHT_GRAY:
|
62
|
-
button = tk.Button(self, text=label, font=('MSゴシック', 20), bg=LIGHT_GRAY, foreground=WHITE)
|
63
|
-
elif color == SMOKE_WHITE:
|
64
|
-
button = tk.Button(self, text=label, font=('MSゴシック', 15), bg=SMOKE_WHITE, foreground=BLACK)
|
65
|
-
elif color == ORANGE:
|
66
|
-
|
72
|
+
button = tk.Button(self, text=text, font=font[bg], bg=bg, fg=fg[bg], command=func)
|
67
73
|
button.grid(column=col, row=row, sticky=(tk.N + tk.S + tk.E + tk.W))
|
68
|
-
button.bind('<Button-1>', func)
|
69
74
|
|
70
75
|
# create entry
|
71
76
|
self.numbox = tk.Entry(self, background=BLACK, foreground=WHITE, font=('MSゴシック', 30), justify=tk.RIGHT)
|
@@ -73,70 +78,31 @@
|
|
73
78
|
self.numbox.grid(column=0, columnspan=6, row=0, sticky=(tk.N + tk.S + tk.E + tk.W))
|
74
79
|
|
75
80
|
# frame flex
|
76
|
-
for i in range(6):
|
81
|
+
for i in range(0, 6):
|
77
82
|
self.columnconfigure(i, weight=1)
|
78
83
|
self.rowconfigure(i, weight=1)
|
79
84
|
|
80
|
-
#
|
85
|
+
# functions
|
81
|
-
def numinput(self
|
86
|
+
def numinput(self): pass
|
82
|
-
pass
|
83
|
-
|
84
|
-
def add(self
|
87
|
+
def add(self): pass
|
85
|
-
pass
|
86
|
-
|
87
|
-
def sub(self
|
88
|
+
def sub(self): pass
|
88
|
-
pass
|
89
|
-
|
90
|
-
def mul(self
|
89
|
+
def mul(self): pass
|
91
|
-
pass
|
92
|
-
|
93
|
-
def div(self
|
90
|
+
def div(self): pass
|
94
|
-
pass
|
95
|
-
|
96
|
-
def equal(self
|
91
|
+
def equal(self): pass
|
97
|
-
pass
|
98
|
-
|
99
|
-
def clear(self
|
92
|
+
def clear(self): pass
|
100
|
-
pass
|
101
|
-
|
102
|
-
def point(self
|
93
|
+
def point(self): pass
|
103
|
-
pass
|
104
|
-
|
105
|
-
def MC(self
|
94
|
+
def MC(self): pass
|
106
|
-
pass
|
107
|
-
|
108
|
-
def MR(self
|
95
|
+
def MR(self): pass
|
109
|
-
pass
|
110
|
-
|
111
|
-
def MS(self
|
96
|
+
def MS(self): pass
|
112
|
-
pass
|
113
|
-
|
114
|
-
def M_plus(self
|
97
|
+
def M_plus(self): pass
|
115
|
-
pass
|
116
|
-
|
117
|
-
def M_sub(self
|
98
|
+
def M_sub(self): pass
|
118
|
-
pass
|
119
|
-
|
120
|
-
def in_tax(self
|
99
|
+
def in_tax(self): pass
|
121
|
-
pass
|
122
|
-
|
123
|
-
def out_tax(self
|
100
|
+
def out_tax(self): pass
|
124
|
-
pass
|
125
|
-
|
126
|
-
def root(self
|
101
|
+
def root(self): pass
|
127
|
-
pass
|
128
|
-
|
129
|
-
def plu_sub(self
|
102
|
+
def plu_sub(self): pass
|
130
|
-
pass
|
131
|
-
|
132
|
-
def CE(self
|
103
|
+
def CE(self): pass
|
133
|
-
pass
|
134
|
-
|
135
|
-
def percent(self
|
104
|
+
def percent(self): pass
|
136
|
-
pass
|
137
|
-
|
138
|
-
def fact(self
|
105
|
+
def fact(self): pass
|
139
|
-
pass
|
140
106
|
|
141
107
|
|
142
108
|
def main():
|
1
range(6)に変更
test
CHANGED
@@ -73,7 +73,7 @@
|
|
73
73
|
self.numbox.grid(column=0, columnspan=6, row=0, sticky=(tk.N + tk.S + tk.E + tk.W))
|
74
74
|
|
75
75
|
# frame flex
|
76
|
-
for i in range(
|
76
|
+
for i in range(6):
|
77
77
|
self.columnconfigure(i, weight=1)
|
78
78
|
self.rowconfigure(i, weight=1)
|
79
79
|
|