Skip to content

Commit c4a49dd

Browse files
committed
changes
1 parent 404313f commit c4a49dd

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

tkinter/thread-queue/main.py renamed to tkinter/thread-queue/main .py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,50 @@ def running(queue):
99

1010
for x in range(5):
1111
text = 'message ' + str(x)
12-
print('put:', text)
12+
print('PUT:', text)
1313
queue.put(text)
14-
time.sleep(3)
14+
time.sleep(4)
1515
queue.put('last')
1616

1717
def check_queue():
18+
global t
1819

1920
text = ''
2021

2122
if not queue.empty():
2223
text = queue.get()
2324
print('get:', text)
24-
#messagebox.showinfo(text, text)
2525
l['text'] = text
2626
else:
2727
print('get: - empty -')
2828

29-
if text != 'last':
30-
root.after(100, check_queue)
31-
29+
if text == 'last':
30+
t = None
31+
else:
32+
root.after(500, check_queue)
33+
34+
def on_click():
35+
global t
36+
37+
if not t:
38+
t = threading.Thread(target=running, args=(queue,))
39+
t.start()
40+
check_queue()
41+
else:
42+
messagebox.showinfo('INFO', 'Process still running')
43+
44+
3245
# --- main ---
3346

47+
t = None
3448
queue = queue.Queue()
35-
36-
t = threading.Thread(target=running, args=(queue,))
37-
t.start()
3849

3950
root = tk.Tk()
4051

4152
l = tk.Label(root, text='', width=15, height=2)
4253
l.pack()
4354

44-
tk.Button(root, text='Button 1', width=15, height=2).pack()
45-
tk.Button(root, text='Button 2', width=15, height=2).pack()
46-
tk.Button(root, text='Button 3', width=15, height=2).pack()
47-
48-
check_queue()
55+
b = tk.Button(root, text='Start', command=on_click, width=15, height=2)
56+
b.pack()
4957

5058
root.mainloop()

0 commit comments

Comments
 (0)