-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxiugaigui1703.py
121 lines (71 loc) · 2.29 KB
/
xiugaigui1703.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 16 20:36:34 2014
@author: duane
"""
from Queue import Queue
import random
import threading
import time
from Tkinter import *
#global numbers
#numbers=0
#Producer thread
def fenlei(num=0):
cv.itemconfig(cv.find_withtag(rtags[num]), fill='red')
cv.after(300,fenlei,num)#500不是次数
cv.after(5000,lambda:root.destroy())
del num
#cv.after(5000,lambda:cv.destroy())#删除cv,但是tk界面还在
class Producer(threading.Thread):
def __init__(self, t_name, queue):
threading.Thread.__init__(self, name=t_name)
self.data=queue
def run(self):
d=random.randrange(8)
print d
#b=b-1
self.data.put(d)
#Consumer thread
class Consumer(threading.Thread):
def __init__(self, t_name, queue):
threading.Thread.__init__(self, name=t_name)
self.data=queue
def run(self):
val=self.data.get()
print val
global numbers
numbers=0
numbers=val+1
print numbers
#self.data.put(c)
#Main thread
def main():
for i in range(10):
queue = Queue()
producer = Producer('Pro.', queue)
consumer = Consumer('Con.', queue)
producer.start()
consumer.start()
producer.join()
consumer.join()
print 'All threads terminate!'
if __name__ == '__main__':
main()
root = Tk()
a=root.winfo_screenheight()
b=root.winfo_screenwidth()
cv=Canvas(root,width=a,height=b,bg='white')
rt=cv.create_text(512,640,text='+',fill='red',font=("Fixdsys",36,"bold"))
cv.pack()
root.after(2000, lambda:cv.itemconfig(rt,text='start'))
rtags = []
for i in range(10):
cv.create_rectangle(700, 500 + i * 30, 900, 530 + i * 30, outline='blue', fill='white', tags='r' + str(i+1))
rtags.append('r' + str(i + 1))
fenlei(num=numbers)
root.after(4900, lambda:cv.itemconfig(rt,text='stop'))
#root.after(5000, lambda:root.destroy())
root.mainloop()
#tianchong.join()
#num=0