質問編集履歴

4

修正

2021/04/12 05:11

投稿

MATLIB
MATLIB

スコア27

test CHANGED
File without changes
test CHANGED
@@ -166,6 +166,8 @@
166
166
 
167
167
 
168
168
 
169
+ flag = True
170
+
169
171
 
170
172
 
171
173
  class WindowType(Enum):
@@ -180,14 +182,6 @@
180
182
 
181
183
 
182
184
 
183
-
184
-
185
- threads = 'True'
186
-
187
- threads1 = 'True'
188
-
189
-
190
-
191
185
  class menu(tkinter.Frame):
192
186
 
193
187
  def __init__(self,master):
@@ -218,9 +212,9 @@
218
212
 
219
213
  def click2(self):
220
214
 
221
- threads1 = threads.replace('True','False')
215
+ flag = False
222
-
216
+
223
- print('aaa',threads1)
217
+ print('aaa',flag)
224
218
 
225
219
 
226
220
 
@@ -256,7 +250,7 @@
256
250
 
257
251
  i = 0
258
252
 
259
- while threads1 is 'True':
253
+ while flag is True:
260
254
 
261
255
  i += 1
262
256
 
@@ -264,7 +258,7 @@
264
258
 
265
259
  time.sleep(1)
266
260
 
267
- if threads1 is 'False':
261
+ if flag is False:
268
262
 
269
263
  break
270
264
 

3

追記

2021/04/12 05:11

投稿

MATLIB
MATLIB

スコア27

test CHANGED
File without changes
test CHANGED
@@ -137,3 +137,155 @@
137
137
 
138
138
 
139
139
  ```
140
+
141
+
142
+
143
+ #追記 while文 フラグ変数版
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+ ```ここに言語を入力
152
+
153
+ # -*- coding: utf-8 -*-
154
+
155
+ import tkinter
156
+
157
+ import tkinter as tk
158
+
159
+ import tkinter.font as font
160
+
161
+ from enum import Enum,auto
162
+
163
+ import time
164
+
165
+ import threading
166
+
167
+
168
+
169
+
170
+
171
+ class WindowType(Enum):
172
+
173
+ itiran=auto()
174
+
175
+ kaiseki=auto()
176
+
177
+ mente=auto()
178
+
179
+ toroku=auto()
180
+
181
+
182
+
183
+
184
+
185
+ threads = 'True'
186
+
187
+ threads1 = 'True'
188
+
189
+
190
+
191
+ class menu(tkinter.Frame):
192
+
193
+ def __init__(self,master):
194
+
195
+ super().__init__(master)
196
+
197
+ self.pack()
198
+
199
+
200
+
201
+ self.master.geometry("800x480")
202
+
203
+ self.master.title("メニュー画面")
204
+
205
+
206
+
207
+ self.create_widgets()
208
+
209
+
210
+
211
+ def click1(self):
212
+
213
+ thread = threading.Thread(target=self.changeLabelText)
214
+
215
+ thread.start()
216
+
217
+
218
+
219
+ def click2(self):
220
+
221
+ threads1 = threads.replace('True','False')
222
+
223
+ print('aaa',threads1)
224
+
225
+
226
+
227
+ def create_widgets(self):
228
+
229
+ # Button
230
+
231
+ font1 = font.Font(size=12)
232
+
233
+ menu_btn1 = tkinter.Button(text='1', bg="#e6e6fa", font=font1, height=11, width=25,command=self.click1)
234
+
235
+ menu_btn1.place(x=30, y=30)
236
+
237
+ menu_btn2 = tkinter.Button(text='2', bg="#e6e6fa", font=font1, height=11, width=25,command=self.click2)
238
+
239
+ menu_btn2.place(x=330, y=30)
240
+
241
+ self.master.label = tk.Label(self.master)
242
+
243
+ self.master.label["font"] = ("Helvetica", 50)
244
+
245
+ self.master.label["bg"] = "green"
246
+
247
+ self.master.label["fg"] = "white"
248
+
249
+ self.master.label.place(x=30, y=250)
250
+
251
+
252
+
253
+
254
+
255
+ def changeLabelText(self):
256
+
257
+ i = 0
258
+
259
+ while threads1 is 'True':
260
+
261
+ i += 1
262
+
263
+ self.master.label["text"] = i
264
+
265
+ time.sleep(1)
266
+
267
+ if threads1 is 'False':
268
+
269
+ break
270
+
271
+
272
+
273
+
274
+
275
+ def main():
276
+
277
+ root = tk.Tk()
278
+
279
+ app = menu(master=root)
280
+
281
+ app.mainloop()
282
+
283
+
284
+
285
+ if __name__ == "__main__":
286
+
287
+ main()
288
+
289
+
290
+
291
+ ```

2

修正

2021/04/12 04:40

投稿

MATLIB
MATLIB

スコア27

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- どなか、対処方法をご教授ください。
9
+ どなか、対処方法をご教授ください。
10
10
 
11
11
 
12
12
 

1

修正

2021/04/11 13:17

投稿

MATLIB
MATLIB

スコア27

test CHANGED
File without changes
test CHANGED
@@ -72,9 +72,7 @@
72
72
 
73
73
  def click2(self):
74
74
 
75
- thread = threading.Thread(target=self.changeLabelText)
76
-
77
- thread.join()
75
+     #2のボタン押下
78
76
 
79
77
 
80
78