teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

8

修正

2020/03/18 07:22

投稿

person
person

スコア224

title CHANGED
File without changes
body CHANGED
@@ -106,7 +106,6 @@
106
106
 
107
107
  def push_close():
108
108
  on_closing()
109
- sub_win.destroy()
110
109
 
111
110
  def push_clear():
112
111
  e_id.delete(0, tk.END)
@@ -114,7 +113,6 @@
114
113
  def push_enter():
115
114
  input_widget.insert(tk.END, e_id.get())
116
115
  on_closing()
117
- sub_win.destroy()
118
116
 
119
117
  def connected(tag):
120
118
  idm = binascii.hexlify(tag.idm) # <class 'byte'>
@@ -134,6 +132,7 @@
134
132
  global clf
135
133
  clf.close() # これがないと応答なしになってしまう
136
134
  thread_nfc.join()
135
+ sub_win.destroy()
137
136
 
138
137
  sub_win = tk.Toplevel()
139
138
 
@@ -153,4 +152,5 @@
153
152
  b_etr = tk.Button(sub_win, text="ENTER", command=push_enter)
154
153
  b_etr.grid()
155
154
 
155
+ sub_win.protocol("WM_DELETE_WINDOW", on_closing)
156
156
  ```

7

追加

2020/03/18 07:22

投稿

person
person

スコア224

title CHANGED
File without changes
body CHANGED
@@ -120,7 +120,7 @@
120
120
  idm = binascii.hexlify(tag.idm) # <class 'byte'>
121
121
  idm = idm.decode() # <class 'str'>
122
122
  e_id.insert(tk.END, idm)
123
- return True # これがないとICを1回かざしたときに複数回認識してしまう
123
+ return True # これがないとICを1回かざしたときに複数回認識してしまう(whileループ時)
124
124
 
125
125
  def ic_read():
126
126
  global clf
@@ -132,7 +132,7 @@
132
132
 
133
133
  def on_closing():
134
134
  global clf
135
- clf.close()
135
+ clf.close() # これがないと応答なしになってしまう
136
136
  thread_nfc.join()
137
137
 
138
138
  sub_win = tk.Toplevel()

6

修正

2020/03/17 02:15

投稿

person
person

スコア224

title CHANGED
File without changes
body CHANGED
@@ -61,7 +61,7 @@
61
61
  win.mainloop()
62
62
  ```
63
63
 
64
- **追記(ソースの間違い)**
64
+ **修正(ソースの間違い)**
65
65
  ```Python
66
66
  # main.py
67
67
 

5

追加

2020/03/17 02:14

投稿

person
person

スコア224

title CHANGED
File without changes
body CHANGED
@@ -59,4 +59,98 @@
59
59
 
60
60
  win.protocol("WM_DELETE_WINDOW", on_closing)
61
61
  win.mainloop()
62
+ ```
63
+
64
+ **追記(ソースの間違い)**
65
+ ```Python
66
+ # main.py
67
+
68
+ import tkinter as tk
69
+
70
+ import input_ic
71
+
72
+
73
+ def push_enter():
74
+ print(e_id.get())
75
+ e_id.delete(0, tk.END)
76
+
77
+
78
+ def push_entry(e, e_id):
79
+ input_ic.input_ic(e, e_id)
80
+
81
+
82
+ if __name__ == "__main__":
83
+ win = tk.Tk()
84
+
85
+ e_id = tk.Entry(win)
86
+ e_id.grid()
87
+
88
+ b_etr = tk.Button(win, text="ENTER", command=push_enter)
89
+ b_etr.grid()
90
+
91
+ e_id.bind("<Button-1>", lambda e:push_entry(e, e_id))
92
+
93
+ win.mainloop()
94
+ ```
95
+
96
+ ```Python
97
+ # input_ic.py
98
+
99
+ import nfc
100
+ import tkinter as tk
101
+ import binascii
102
+ import threading
103
+
104
+
105
+ def input_ic(e, input_widget):
106
+
107
+ def push_close():
108
+ on_closing()
109
+ sub_win.destroy()
110
+
111
+ def push_clear():
112
+ e_id.delete(0, tk.END)
113
+
114
+ def push_enter():
115
+ input_widget.insert(tk.END, e_id.get())
116
+ on_closing()
117
+ sub_win.destroy()
118
+
119
+ def connected(tag):
120
+ idm = binascii.hexlify(tag.idm) # <class 'byte'>
121
+ idm = idm.decode() # <class 'str'>
122
+ e_id.insert(tk.END, idm)
123
+ return True # これがないとICを1回かざしたときに複数回認識してしまう
124
+
125
+ def ic_read():
126
+ global clf
127
+ clf = nfc.ContactlessFrontend("usb") # 接続
128
+ try:
129
+ clf.connect( rdwr={"on-connect": connected} ) # 認識
130
+ finally:
131
+ clf.close() # 切断
132
+
133
+ def on_closing():
134
+ global clf
135
+ clf.close()
136
+ thread_nfc.join()
137
+
138
+ sub_win = tk.Toplevel()
139
+
140
+ thread_nfc = threading.Thread(target=ic_read)
141
+ thread_nfc.start()
142
+
143
+ e_id = tk.Entry(sub_win)
144
+ e_id.insert(tk.END, input_widget.get())
145
+ e_id.grid()
146
+
147
+ b_cls = tk.Button(sub_win, text="CLOSE", command=push_close)
148
+ b_cls.grid()
149
+
150
+ b_clr = tk.Button(sub_win, text="CLEAR", command=push_clear)
151
+ b_clr.grid()
152
+
153
+ b_etr = tk.Button(sub_win, text="ENTER", command=push_enter)
154
+ b_etr.grid()
155
+
62
156
  ```

4

追加

2020/03/17 02:12

投稿

person
person

スコア224

title CHANGED
File without changes
body CHANGED
@@ -7,7 +7,7 @@
7
7
  自分なりに考えて下のようになりました。
8
8
 
9
9
  上手く動作しないので、どこをどう直せばよいか教えてください。
10
- (ICを読み込ませずにウィンドウを閉じるとができない
10
+ (ICを読み込ませずにウィンドウを閉じようとすると、閉じるまでに時間かかりそれまはフリーズ状態
11
11
 
12
12
  ```Python
13
13
  import nfc
@@ -23,6 +23,7 @@
23
23
  e_id.delete(0, tk.END)
24
24
 
25
25
  def ic_read():
26
+ global clf # on_close() でも扱うことがあるため
26
27
  clf = nfc.ContactlessFrontend("usb") # 接続
27
28
  try:
28
29
  clf.connect( rdwr={"on-connect": connected} ) # 認識
@@ -36,6 +37,8 @@
36
37
  return True
37
38
 
38
39
  def on_closing():
40
+ global clf
41
+ clf.close() # ICを読み込まずにウィンドウを閉じようとするときに、これがないとフリーズではなく応答なしになってしまう
39
42
  thread_nfc.join()
40
43
  win.destroy()
41
44
 

3

修正

2020/02/28 01:27

投稿

person
person

スコア224

title CHANGED
File without changes
body CHANGED
@@ -7,7 +7,7 @@
7
7
  自分なりに考えて下のようになりました。
8
8
 
9
9
  上手く動作しないので、どこをどう直せばよいか教えてください。
10
- (読み取りはするが、ウィンドウを閉じることができない)
10
+ ICを読み込ませずにウィンドウを閉じることができない)
11
11
 
12
12
  ```Python
13
13
  import nfc
@@ -37,6 +37,7 @@
37
37
 
38
38
  def on_closing():
39
39
  thread_nfc.join()
40
+ win.destroy()
40
41
 
41
42
  if __name__ == "__main__":
42
43
  thread_nfc = threading.Thread(target=ic_read)

2

修正

2020/02/28 00:57

投稿

person
person

スコア224

title CHANGED
File without changes
body CHANGED
@@ -7,12 +7,13 @@
7
7
  自分なりに考えて下のようになりました。
8
8
 
9
9
  上手く動作しないので、どこをどう直せばよいか教えてください。
10
- (読み取りはするが、読み取った後にウィンドウがてしまう
10
+ (読み取りはするが、ウィンドウを閉じることできない)
11
11
 
12
12
  ```Python
13
13
  import nfc
14
14
  import tkinter as tk
15
15
  import binascii
16
+ import threading
16
17
 
17
18
  def push_clear():
18
19
  e_id.delete(0, tk.END)
@@ -32,9 +33,15 @@
32
33
  idm = binascii.hexlify(tag.idm) # <class 'byte'>
33
34
  idm = idm.decode() # <class 'str'>
34
35
  e_id.insert(tk.END, idm)
35
- return True # 複数回かざす場合にこれがないと瞬間的に連続認識してしまう(?)
36
+ return True
36
37
 
38
+ def on_closing():
39
+ thread_nfc.join()
40
+
37
41
  if __name__ == "__main__":
42
+ thread_nfc = threading.Thread(target=ic_read)
43
+ thread_nfc.start()
44
+
38
45
  win = tk.Tk()
39
46
 
40
47
  e_id = tk.Entry(win)
@@ -46,7 +53,6 @@
46
53
  b_ent = tk.Button(win, text="ENTER", command=push_enter)
47
54
  b_ent.grid()
48
55
 
49
- ic_read() #意図した動作をしない
56
+ win.protocol("WM_DELETE_WINDOW", on_closing)
50
-
51
57
  win.mainloop()
52
58
  ```

1

追加

2020/02/28 00:54

投稿

person
person

スコア224

title CHANGED
File without changes
body CHANGED
@@ -1,9 +1,13 @@
1
1
  tkinterのテキストボックスにICのIDを入力したい。
2
2
 
3
- ICは1回読めればいいです
3
+ ICリーダRC-S380を使用
4
4
 
5
+ ICは1回読めればいいです。もう1回かざしなおしても読み取らなくていいです。
6
+
5
7
  自分なりに考えて下のようになりました。
8
+
6
9
  上手く動作しないので、どこをどう直せばよいか教えてください。
10
+ (読み取りはするが、読み取った後にウィンドウが開いてしまう)
7
11
 
8
12
  ```Python
9
13
  import nfc