我正在设计一个护士呼叫系统来进行服务。我正在使用python来实现该软件。每个房间都会包含两个按钮调用和取消。当按下呼叫按钮时,相应的房间和床将显示在护士站上,直到按下取消按钮。如果有多个呼叫待处理,它将以FIFO为基础显示。服务我写的功能。如果首先提供来自中间或顶部的呼叫,我必须在tkinter窗口上向上移动待处理的呼叫
def service():
global servicependingid1,servicependingid2,servicependingid3,servicependingid4
msg1="call from "
msg2=" bed "
if receiveddata== "SBid1" and servicependingid1:
if servicependingid2>servicependingid1:
servicependingid2=servicependingid2-1
id2position= Label(window,text=(msg1+id2room+msg2+id2bed),fg="yellow",bg="blue",font=("Helvetica", size))
id2position.grid(row=servicependingid2,column=2,sticky=W)
id2servicetrack=servicependingid2
if servicependingid3>servicependingid1:
servicependingid3=servicependingid3-1
id3position= Label(window,text=(msg1+id3room+msg2+id3bed),fg="yellow",bg="blue",font=("Helvetica", size))
id3position.grid(row=servicependingid3,column=2,sticky=W)
id3servicetrack=servicependingid3
if receiveddata== "SBid2" and servicependingid2:
if servicependingid1>servicependingid2:
servicependingid1=servicependingid1-1
id2position= Label(window,text=(msg1+id2room+msg2+id2bed),fg="yellow",bg="blue",font=("Helvetica", size))
id2position.grid(row=servicependingid1,column=2,sticky=W)
id2servicetrack=servicependingid2
if servicependingid3>servicependingid2:
servicependingid3=servicependingid3-1
id3position= Label(window,text=(msg1+id3room+msg2+id3bed),fg="yellow",bg="blue",font=("Helvetica", size))
id3position.grid(row=servicependingid3,column=2,sticky=W)
id3servicetrack=servicependingid3
如果房间和床没有大,那么这个approch会出问题。有没有更好的方式来实现这个功能。是否有任何python指令可以将待处理的呼叫向上移动?
答案 0 :(得分:1)
听起来你想要使用(有序)列表。
roomsToService = [] # list of rooms to service
def callFromRoom(roomNumber):
if roomNumber in roomsToService:
return
roomsToService.append(roomNumber)
def cancelFromRoom(roomNumber):
if roomNumber not in roomsToService:
return
roomsToService.remove(roomNumber)
def showRoomsToService():
print(roomsToService)
callFromRoom(302)
callFromRoom(606)
callFromRoom(100)
showRoomsToService() # [302, 606, 100]
cancelFromRoom(606)
showRoomsToService() # [302, 100]