操作系统上机作业:生产者,消费者算法(python,tkinter写)
import tkinter as tk
root = tk.Tk()
root.title("生产者消费者问题")
root.geometry('800x400')
on_hit1 = False
on_hit2 = False
on_hit3 = False
on_hit4 = False
on_hit5 = False
on_hit6 = False
def del_num():
text1.delete(0)
text1.insert(0,text2.get())
text2.delete(0)
text2.insert(0,text3.get())
text3.delete(0)
text3.insert(0,block1.get())
block1.delete(0)
block1.insert(0,block2.get())
block2.delete(0)
block2.insert(0,block3.get())
block3.delete(0)
def del_xb():
xb1.delete(0,2)
xb1.insert(0,xb2.get())
xb2.delete(0,2)
xb2.insert(0,xb3.get())
xb3.delete(0,2)
def insert_num1():
global on_hit1,on_hit2,on_hit3,on_hit4,on_hit5,on_hit6
if xb1.get() == '消1':
del_xb()
xbt1.config(state='normal')
elif xb1.get() == '消2':
del_xb()
xbt2.config(state='normal')
elif xb1.get() == '消3':
del_xb()
xbt3.config(state='normal')
elif on_hit1 == False:
text1.insert('insert',1)
on_hit1 = True
elif on_hit2 == False:
text2.insert('insert',1)
on_hit2 = True
elif on_hit3 == False:
text3.insert('insert',1)
on_hit3 = True
elif on_hit4 == False:
block1.insert('insert',1)
sbt1.config(state='disabled')
on_hit4 = True
elif on_hit5 == False:
block2.insert('insert',1)
sbt1.config(state='disabled')
on_hit5 = True
elif on_hit6 == False:
block3.insert('insert',1)
on_hit6 = True
sbt1.config(state='disabled')
sbt2.config(state='disabled')
sbt3.config(state='disabled')
def insert_num2():
global on_hit1,on_hit2,on_hit3,on_hit4,on_hit5,on_hit6
if xb1.get() == '消1':
del_xb()
xbt1.config(state='normal')
elif xb1.get() == '消2':
del_xb()
xbt2.config(state='normal')
elif xb1.get() == '消3'