回答編集履歴

6

バグ修正

2020/01/15 04:00

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -86,7 +86,7 @@
86
86
 
87
87
 
88
88
 
89
- tk.Button(root, text="実行", command=calcurate).place(x=180, y=150)
89
+ tk.Button(root, text="実行", command=calculate).place(x=180, y=150)
90
90
 
91
91
 
92
92
 

5

バグ修正

2020/01/15 04:00

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -86,7 +86,7 @@
86
86
 
87
87
 
88
88
 
89
- tk.Button(root, text="実行", command=btn_click).place(x=180, y=150)
89
+ tk.Button(root, text="実行", command=calcurate).place(x=180, y=150)
90
90
 
91
91
 
92
92
 

4

バグ修正

2020/01/15 03:54

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -41,8 +41,6 @@
41
41
  }
42
42
 
43
43
 
44
-
45
- def btn_click():
46
44
 
47
45
  def calculate():
48
46
 

3

処理分割

2020/01/15 03:53

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -44,11 +44,15 @@
44
44
 
45
45
  def btn_click():
46
46
 
47
+ def calculate():
48
+
47
- value = int(entry.get() or 0)
49
+ value = int(entry.get() or 0) # 空欄のときは0
50
+
51
+ calc = action.get(combo.get(), nop) # 選択肢にないときは nop関数
48
52
 
49
53
  answer.delete(0, tk.END)
50
54
 
51
- answer.insert(0, action.get(combo.get(), nop)(value))
55
+ answer.insert(0, calc(value))
52
56
 
53
57
 
54
58
 

2

説明追記

2020/01/15 03:09

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -1,4 +1,4 @@
1
- こん感じ
1
+ 選択肢と選択後の関数を辞書データにしておくのが楽のでは
2
2
 
3
3
 
4
4
 

1

変数名変更

2020/01/15 03:00

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -44,11 +44,11 @@
44
44
 
45
45
  def btn_click():
46
46
 
47
- num = int(value.get() or 0)
47
+ value = int(entry.get() or 0)
48
48
 
49
49
  answer.delete(0, tk.END)
50
50
 
51
- answer.insert(0, action.get(combo.get(), nop)(num))
51
+ answer.insert(0, action.get(combo.get(), nop)(value))
52
52
 
53
53
 
54
54
 
@@ -78,9 +78,9 @@
78
78
 
79
79
 
80
80
 
81
- value = tk.Entry(width=20)
81
+ entry = tk.Entry(width=20)
82
82
 
83
- value.place(x=140, y=50)
83
+ entry.place(x=140, y=50)
84
84
 
85
85
 
86
86