Tkinter窗口管理

时间:2015-05-13 06:44:45

标签: python tkinter raspberry-pi

我正在设计一个护士呼叫系统来进行服务。我正在使用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指令可以将待处理的呼叫向上移动?

1 个答案:

答案 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]