欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python实现简易自习室座位预约系统

程序员文章站 2022-06-25 12:33:36
目录3.1 orderlist.json:4.1 slotcard_in4.2 slotcard_out5.2 slotcard_in 刷卡进入5.4 slotcard_out 刷卡离开或暂离6.1...

刚学习python不久,如有问题希望能得到指正

0 效果

座位选择框

python实现简易自习室座位预约系统

python实现简易自习室座位预约系统

1 关于所需库

python 环境中需要安装下列 python 包:

  • pyside2
  • datetime
  • json
  • argparse

2 关于座位选择框

选择框内桌子数量,大小,样式以及每个椅子位置都是可变的,例如我们可以将桌子颜色和是否圆角改变:

python实现简易自习室座位预约系统

这主要依靠seatinf.json内的信息,展示如下:

{
    "tablenum": 6,
    "tablepos": [
        [0.02,0.15],
        [0.35,0.15],
        [0.68,0.15],
        [0.02,0.65],
        [0.35,0.65],
        [0.68,0.65]
    ],
    "tablesize": [
        [0.25,0.2],
        [0.25,0.2],
        [0.25,0.2],
        [0.25,0.2],
        [0.25,0.2],
        [0.25,0.2]
    ],
    "tabletype": [
        0,1,2,0,0,0
    ],
    "tabless": [
        "qlabel{background: rgb(245,245,245);color:rgb(92,92,92);border-radius:50px;border: 3px solid rgb(142,142,142)}",
        "qlabel{background: rgb(245,245,245);color:rgb(92,92,92);border: 3px solid rgb(142,142,142)}",
        "qlabel{background: rgb(221,217,195);color:rgb(92,92,92);border: 3px solid rgb(142,142,142)}"
    ],
    "tableid": [
        "a","b","c","d","e","f"
    ],
    "chairnum": [
        6,6,6,6,6,6
    ],
    "chairpos": [
        [
            [0.04,-0.08],
            [0.105,-0.08],
            [0.17,-0.08],
            [0.04,0.21],
            [0.105,0.21],
            [0.17,0.21]
        ],
        [
            [0.04,-0.08],
            [0.105,-0.08],
            [0.17,-0.08],
            [0.04,0.21],
            [0.105,0.21],
            [0.17,0.21]
        ],[
            [0.04,-0.08],
            [0.105,-0.08],
            [0.17,-0.08],
            [0.04,0.21],
            [0.105,0.21],
            [0.17,0.21]
        ],[
            [0.04,-0.08],
            [0.105,-0.08],
            [0.17,-0.08],
            [0.04,0.21],
            [0.105,0.21],
            [0.17,0.21]
        ],[
            [0.04,-0.08],
            [0.105,-0.08],
            [0.17,-0.08],
            [0.04,0.21],
            [0.105,0.21],
            [0.17,0.21]
        ],[
            [0.04,-0.08],
            [0.105,-0.08],
            [0.17,-0.08],
            [0.04,0.21],
            [0.105,0.21],
            [0.17,0.21]
        ]
    ],
    "chairsize": [
        0.032,0.07
    ],
    "chairss_w": "background: rgb(242,242,242);border-radius:15px;border: 3px solid rgb(74,69,42)",
    "chairss_k": "background: rgb(64,64,64);border-radius:15px;border: 3px solid rgb(74,69,42)",
    "chairss_r": "background: rgb(149,55,43);border-radius:15px;border: 3px solid rgb(74,69,42)",
    "mapsize": [
        2,2
    ]
}

3 关于申请表和座位被占情况

由于只是为了模拟过程,现申请表以及座位被占情况分别存储在orderlist.json和occupied.json中:

3.1 orderlist.json:

"[[\"a1\", \"a2\", \"a3\", \"a4\", \"a5\", \"a6\", \"b1\", \"b2\", \"b3\", \"b4\", \"b5\", \"b6\", \"c1\", \"c2\", \"c3\", \"c4\", \"c5\", \"c6\", \"d1\", \"d2\", \"d3\", \"d4\", \"d5\", \"d6\", \"e1\", \"e2\", \"e3\", \"e4\", \"e5\", \"e6\", \"f1\", \"f2\", \"f3\", \"f4\", \"f5\", \"f6\"], [\"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"1816000xxxx\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\"], [\"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"temp\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\"]]"

3.2 occupied.json:

"{\"a1\": false, \"a2\": false, \"a3\": false, \"a4\": false, \"a5\": false, \"a6\": false, \"b1\": false, \"b2\": false, \"b3\": false, \"b4\": false, \"b5\": false, \"b6\": false, \"c1\": false, \"c2\": false, \"c3\": false, \"c4\": true, \"c5\": false, \"c6\": false, \"d1\": false, \"d2\": false, \"d3\": false, \"d4\": false, \"d5\": false, \"d6\": false, \"e1\": false, \"e2\": false, \"e3\": false, \"e4\": false, \"e5\": false, \"e6\": false, \"f1\": false, \"f2\": false, \"f3\": false, \"f4\": false, \"f5\": false, \"f6\": false}"

4 关于命令行参数

我们使用命令行代码模拟刷卡过程,同时我们也设置了预约和申请暂离的命令行代码:

4.1 slotcard_in

python slotcard_in.py -i="xxxxxxxxxxx"
python slotcard_in.py --student-id="xxxxxxxxxxx"

4.2 slotcard_out

python slotcard_out.py -i="xxxxxxxxxxx"
python slotcard_out.py --student-id="xxxxxxxxxxx"

4.3 cmd_order

'''
test code:
--------------------------------
see map:
python cmd_order.py
--------------------------------
order seat: 
python cmd_order.py -i="xxxxxxxxxxx" -n="xxx" -s="a1"

-h   --help         show the help message and exit
-i   --student-id   student id
-n   --student-name student name
-s   --seatpos      seat id  
'''

4.4 cmd_leave

'''
test code:
----------------------------------------------
leave for temp
python cmd_leave.py -i="xxxxxxxxxxx" -t="temp"
----------------------------------------------
leave
python cmd_leave.py -i="xxxxxxxxxxx" -t="free"  
[or]
python cmd_leave.py -i="xxxxxxxxxxx" 

-h   --help         show the help message and exit
-i   --student-id   student id
-t   --leave-type   temp/free 
'''

5 关于命令行输出

5.1 cmd_order 预约

> python cmd_order.py
[seat]============================
可预约座位:

 ▇ a2 a3 a4 a5 a6
 b1 b2 b3 b4 b5 b6
 c1 c2 c3 c4 c5 c6
 d1 d2 d3 d4 d5 d6
 e1 e2 e3 e4 e5 e6
 f1 f2 f3 f4 f5 f6

> python cmd_order.py -i="18160000000" -n="xxx" -s="a1"
[book error]========================
座位已被占,请选择其他位置申请

> python cmd_order.py -i="18160000000" -n="xxx" -s="a100"
[book error]========================
座位编号格式不正确

> python cmd_order.py -i="18160000000" -n="xxx" -s="a2"
[book]===========================================
2021-05-31 18:04:35
姓名:xxx
学号:18160000000
座次:a2
预约成功!
-------------------------------------------------
注意事项:
1、预约成功后请在30分钟内到达,否则预约信息将失效。
2、进入自习室前请刷校园卡核验信息。
3、如要暂离请cmd运行如下代码:
   python cmd_leave.py -i='xxxxxxxxxxx' -t='temp'
4、离开、取消预约请cmd运行如下代码:
   python cmd_leave.py -i='xxxxxxxxxxx' -t='free'

> python cmd_order.py -i="18160000000" -n="xxx" -s="a3"
[book error]========================
请勿重复预约

5.2 slotcard_in 刷卡进入

> python slotcard_in.py -i="1816000xxxx"
[in error]==========================
非本校校园卡或已超时

> python slotcard_in.py -i="18160000000"
[in]================================
预约时间:2021-05-31 18:04:35
校园卡号:18160000000
座次:a2

5.3 cmd_leave 申请离开或暂离

> python cmd_leave.py -i="1816000xxxx" -t="temp"
[out error]=========================
可能输入了错误的校园卡号

> python cmd_leave.py -i="18160000000" -t="temp"
[out]===============================
已进行暂离申请

> python cmd_leave.py -i="18160000000" -t="free"
[out]===============================
已释放位置

5.4 slotcard_out 刷卡离开或暂离

> python slotcard_out.py -i="18160000000"
[out]===============================
暂离时间:2021-05-31 18:23:09
校园卡号:18160000000
座次:a1

> python slotcard_out.py -i="1816000xxxx"
[out error]=========================
请更换卡片再次尝试

6 关于界面代码

6.1 ordersystem.py

from pyside2.qtwidgets import qapplication, qwidget,qscrollarea
from pyside2.qtwidgets import qlabel,qpushbutton,qlineedit
from pyside2.qtgui import qicon,qfont
from pyside2.qtcore import qt
import sys
sys.path.append("...")
import json
import datetime
from orderdatadisplay import orderdisplay
from infoperate import occupyseat,order,timeoutdetection,alreadyoreder


class window_main(qwidget):
    def __init__(self,width=700,height=840):
        super().__init__() 
        self.setwindowtitle("book seat online")
        timeoutdetection()

        self.width=width
        self.height=height
        self.selectedid=""
        self.selectedbtn=[]
        self.icopath="./gallery/icon.ico"

        # 字体标签
        title_qf=qfont()
        title_qf.setpointsize(11)
        title_qf.setbold(true)
        title_qf.setfamily("cambria")
        main_qf=qfont()
        main_qf.setpointsize(27)
        main_qf.setbold(true)
        main_qf.setfamily("cambria")
        inf_qf=qfont()
        inf_qf.setpointsize(10)
        inf_qf.setbold(true)
        inf_qf.setfamily("cambria")
        table_qf=qfont()
        table_qf.setpointsize(16)
        table_qf.setbold(true)
        table_qf.setfamily("cambria")
        # ---
        self.qf_part_title=title_qf         # 框标题字体标签
        self.qf_main_title=main_qf          # 主标题字体标签
        self.qf_state_explain=inf_qf        # 状态标签解释文本字体标签
        self.qf_inf_title=title_qf          # 信息标题字体标签
        self.qf_inf_text=inf_qf             # 信息文本字体标签
        self.qf_table_name=table_qf         # 桌子编号信息标签

        # 样式表
        self.ss_part_frame="qlabel{background: rgb(245,245,245);color:rgb(92,92,92);border-radius:8px;border: 2.5px solid rgb(122,122,122)}"
        self.ss_part_title="qlabel{background: rgb(245,245,245);color:rgb(92,92,92)}"
        self.ss_main_title="qlabel{background: rgb(245,245,245);color:rgb(92,92,92);border-radius:50px;border: 3px solid rgb(142,142,142)}"
        self.ss_state_frame="qlabel{background: rgb(245,245,245);border-radius:5px;border: 3px solid rgb(172,172,172)}"
        self.ss_w="qlabel{background: rgb(242,242,242);border-radius:9px;border: 3px solid rgb(74,69,42)}"
        self.ss_k="qlabel{background: rgb(64,64,64);border-radius:9px;border: 3px solid rgb(74,69,42)}"
        self.ss_r="qlabel{background: rgb(149,55,43);border-radius:9px;border: 3px solid rgb(74,69,42)}"
        self.ss_state_explain="qlabel{background: rgb(214,219,233);color:rgb(92,92,92)}"
        self.ss_inf_title="qlabel{background: rgb(230,230,230);color:rgb(82,82,82);border-radius:8px}"
        self.ss_text_line="qlineedit{border-radius:3px;background: rgb(205,205,205);color:rgb(82,82,82)}"
        self.ss_book_btn="color:rgb(255,255,255);background: rgb(79,148,204)"

        # path=sys.argv[0]
        # path=path[0:path.rfind("/")]
        f=open("./config/seatinf.json","r")
        seatinf=json.load(f)
        f=open("./config/occupied.json","r")
        seatoccupied=json.load(f)
        self.seatinf=seatinf
        self.seatoccupied=json.loads(seatoccupied)

        self.setsize()
        self.seticon()
        self.partition()
        self.setstateexp()
        self.setinfbox()
        self.setmap()
        self.setbookbtn()    
    # ================================================================================================
    # 回调函数部分:
    def selectedpos(self):# 座位选择回调
        btn=self.sender()
        tempselectedid=btn.property("chairid")
        if not self.seatoccupied[tempselectedid]:
            if len(self.selectedid)==0:
                self.selectedid=tempselectedid
                self.selectedbtn=btn
                btn.setstylesheet(self.seatinf["chairss_r"])
                self.selectedbox.settext(" 当前选择:  "+tempselectedid)
            else:
                self.selectedbtn.setstylesheet(self.seatinf["chairss_w"])
                self.selectedbtn=btn
                btn.setstylesheet(self.seatinf["chairss_r"])
                self.selectedid=tempselectedid
                self.selectedbox.settext(" 当前选择:  "+tempselectedid)

    def bookseat(self):
        if not len(self.selectedid)==0:
            if alreadyoreder(self.infbox_id.text()):
                print("================================")
                print("请勿重复预约")
                print(" ")
            else:
                nowdate=datetime.datetime.now()
                nowdatestr=nowdate.strftime('%y-%m-%d %h:%m:%s')
                print("================================")
                print(nowdatestr)
                print("姓名:"+self.infbox_name.text())
                print("学号:"+self.infbox_id.text())
                print("座次:"+self.selectedid)
                print(" ")
                # myapp.exit()
                # app = qapplication.instance()
                # if app is none: 
                #     app = qapplication(sys.argv)
                self.window_disp= orderdisplay(self.infbox_name.text(),
                            self.infbox_id.text(),
                            nowdatestr,
                            self.selectedid,700,840)
                self.window_disp.show()
                self.close()

                occupyseat(self.selectedid)
                order(self.infbox_id.text(),nowdatestr,self.selectedid)

            
            


    # ================================================================================================
    # 框架构造函数部分:
    def setsize(self):# 调整框架大小
        self.setgeometry(80,80,self.width,self.height)
        self.setmaximumsize(self.width,self.height)
        self.setminimumsize(self.width,self.height)

    def seticon(self):# 设置图标
        appicon=qicon(self.icopath)
        self.setwindowicon(appicon)

    def setstateexp(self):# 绘制状态解释框
        width=self.width
        height=self.height
        self.part0=qlabel(self)
        self.part0.setgeometry(0.66*width,0.045*height,
                               0.28*width,0.14*height)
        self.part0.setstylesheet(self.ss_state_frame)

        # ---color bar--------------------------------------------------------------------
        self.cb1=qlabel(self)
        self.cb1.setgeometry(0.68*width,0.06*height,0.05*width,0.03*height)
        self.cb1.setstylesheet(self.ss_w) 
        self.cb2=qlabel(self)
        self.cb2.setgeometry(0.68*width,(0.06+0.04)*height,0.05*width,0.03*height)
        self.cb2.setstylesheet(self.ss_k) 
        self.cb3=qlabel(self)
        self.cb3.setgeometry(0.68*width,(0.06+0.08)*height,0.05*width,0.03*height)
        self.cb3.setstylesheet(self.ss_r) 

        # ---color bar 解释文本-------------------------------------------------------------
        self.plaintext1=qlabel(self)
        self.plaintext1.setgeometry(0.76*width,(0.059)*height,0.15*width,0.032*height)
        self.plaintext1.setstylesheet(self.ss_state_explain)
        self.plaintext1.settext(" 可选择")
        self.plaintext1.setfont(self.qf_state_explain)
        self.plaintext2=qlabel(self)
        self.plaintext2.setgeometry(0.76*width,(0.059+0.04)*height,0.15*width,0.032*height)
        self.plaintext2.setstylesheet(self.ss_state_explain)
        self.plaintext2.settext(" 已被选")
        self.plaintext2.setfont(self.qf_state_explain)
        self.plaintext3=qlabel(self)
        self.plaintext3.setgeometry(0.76*width,(0.059+0.08)*height,0.15*width,0.032*height)
        self.plaintext3.setstylesheet(self.ss_state_explain)
        self.plaintext3.settext(" 当前选择")
        self.plaintext3.setfont(self.qf_state_explain)

    def setinfbox(self):
        width=self.width
        height=self.height
        # ---信息标题------------------------------------------
        self.inftitle_name=qlabel(self)
        self.inftitle_name.setgeometry(0.09*width,0.28*height,
                                       0.16*width,0.05*height)
        self.inftitle_name.setstylesheet(self.ss_inf_title)
        self.inftitle_name.settext("   姓名:")
        self.inftitle_name.setfont(self.qf_inf_title)
        # ---
        self.inftitle_id=qlabel(self)
        self.inftitle_id.setgeometry(0.09*width,0.36*height,
                                     0.16*width,0.05*height)
        self.inftitle_id.setstylesheet(self.ss_inf_title)
        self.inftitle_id.settext("   学号:")
        self.inftitle_id.setfont(self.qf_inf_title)

        # ---信息文本框------------------------------------------
        self.infbox_name=qlineedit(self) 
        self.infbox_name.settext("示例:李华") 
        self.infbox_name.move(0.3*width,0.281*height)  
        self.infbox_name.resize(0.6*width,0.048*height)
        self.infbox_name.setfont(self.qf_inf_text)
        self.infbox_name.setstylesheet(self.ss_text_line)
        #self.infbox_name.textchanged.connect(self.colorcheckfunc)

        self.infbox_id=qlineedit(self) 
        self.infbox_id.settext("示例:xxxxxxxxxxx") 
        self.infbox_id.move(0.3*width,0.361*height)  
        self.infbox_id.resize(0.6*width,0.048*height)
        self.infbox_id.setfont(self.qf_inf_text)
        self.infbox_id.setstylesheet(self.ss_text_line)
        #self.infbox_id.textchanged.connect(self.colorcheckfunc)

    def partition(self):# 绘制框线分布
        width=self.width
        height=self.height
        # ---标题框---------------------------------------------------
        self.part0=qlabel(self)
        self.part0.setgeometry(0.05*width,0.045*height,
                               0.52*width,0.14*height)
        self.part0.setstylesheet(self.ss_main_title)
        self.part0.setalignment(qt.aligncenter)
        self.part0.settext(" 自习室预约")
        self.part0.setfont(self.qf_main_title)
        # self.part0title=qlabel(self)
        # self.part0title.setgeometry(0.098*width,0.06*height,
        #                             0.43*width,0.11*height)
        # self.part0title.setstylesheet(self.ss_part_title)
        # self.part0title.settext(" 自习室预约")
        # self.part0title.setfont(self.qf_main_title)
        
        # ---信息填写框-----------------------------------------------
        self.part1=qlabel(self)
        self.part1.setgeometry(0.04*width,0.23*height,
                               0.92*width,0.24*height)
        self.part1.setstylesheet(self.ss_part_frame)
        self.part1title=qlabel(self)
        self.part1title.setgeometry(0.08*width,0.21*height,
                                    0.15*width,0.04*height)
        self.part1title.setstylesheet(self.ss_part_title)
        self.part1title.settext(" 信息填写")
        self.part1title.setfont(self.qf_part_title)
    
        # ---座位选择框------------------------------------------------
        self.part2=qlabel(self)
        self.part2.setgeometry(0.04*width,0.53*height,
                               0.92*width,0.355*height)
        self.part2.setstylesheet(self.ss_part_frame)
        self.part1title=qlabel(self)
        self.part1title.setgeometry(0.08*width,0.51*height,
                                    0.15*width,0.04*height)
        self.part1title.setstylesheet(self.ss_part_title)
        self.part1title.settext(" 座位选择")
        self.part1title.setfont(self.qf_part_title)
        # ================================================================================================
        # 可滑动区域部分:
    def setmap(self):
        width=self.width
        height=self.height
        self.map=qscrollarea(self)
        self.map.setgeometry(0.05*width,0.545*height,
                             0.9*width,0.325*height)
        self.drawmap()
        self.map.setwidget(self.mapcontent)


    def drawmap(self):# 绘制座位地图
        self.mapcontent=qwidget(self)   
        boxwidth=0.9*self.width
        boxheight=0.325*self.height
        
        seatinf=self.seatinf
        seatoccupied=self.seatoccupied
        

        mapwidth=boxwidth*seatinf["mapsize"][0]
        mapheight=boxheight*seatinf["mapsize"][1]
        tablesize=seatinf["tablesize"]
        tablepos=seatinf["tablepos"]
        chairsize=seatinf["chairsize"]
        chairpos=seatinf["chairpos"]

        self.mapcontent.setgeometry(0,0,mapwidth,mapheight) 
        self.mapcontent.setmaximumsize(mapwidth,mapheight)
        self.mapcontent.setminimumsize(mapwidth,mapheight)
        
        for i in range(0,seatinf["tablenum"]):
            table=qlabel(self.mapcontent)
            table.setgeometry(tablepos[i][0]*mapwidth,tablepos[i][1]*mapheight,
                              tablesize[i][0]*mapwidth,tablesize[i][1]*mapheight)
            table.settext(seatinf["tableid"][i])
            table.setfont(self.qf_table_name)
            table.setalignment(qt.aligncenter)
            table.setstylesheet(seatinf["tabless"][seatinf["tabletype"][i]])
            for j in range(0,seatinf["chairnum"][i]):
                chairbnt=qpushbutton(self.mapcontent)
                chairbnt.setgeometry((tablepos[i][0]+chairpos[i][j][0])*mapwidth,
                                     (tablepos[i][1]+chairpos[i][j][1])*mapheight,
                                     chairsize[0]*mapwidth,
                                     chairsize[1]*mapheight)

                chairid=seatinf["tableid"][i]+str(j+1)
                if seatoccupied[chairid]:
                    chairbnt.setstylesheet(seatinf["chairss_k"])
                else:
                    chairbnt.setstylesheet(seatinf["chairss_w"])

                chairbnt.setproperty("chairid",chairid)
                chairbnt.clicked.connect(self.selectedpos)

    def setbookbtn(self):
        width=self.width
        height=self.height
        self.selectedbox=qlabel(self)
        self.selectedbox.setgeometry(0.54*width,(0.92)*height,0.22*width,0.05*height)
        self.selectedbox.setstylesheet(self.ss_state_explain)
        self.selectedbox.settext(" 当前选择:")
        self.selectedbox.setfont(self.qf_inf_title)
        
        self.bookbtn=qpushbutton(self)
        self.bookbtn.setgeometry(0.79*width,(0.92)*height,0.16*width,0.05*height)
        self.bookbtn.setstylesheet(self.ss_book_btn)
        self.bookbtn.settext("预约")
        self.bookbtn.setfont(self.qf_inf_title)
        self.bookbtn.clicked.connect(self.bookseat)
# ===========================================================================================
# 函数调用:
myapp = qapplication(sys.argv)
window_main = window_main(700,840)
window_main.show()
sys.exit(myapp.exec_())

6.2 orderdatadisplay.py

from pyside2.qtwidgets import qapplication, qwidget
from pyside2.qtwidgets import qlabel,qpushbutton
from pyside2.qtgui import qicon,qfont,qpixmap
from pyside2.qtcore import qt
import sys
sys.path.append("...")
import datetime
from infoperate import freeseat,setstring

class window_disp(qwidget):
    def __init__(self,studentname,studentid,booktime,seatid,width=700,height=840):
        super().__init__() 
        self.setwindowtitle("order successfully")
        

        self.studentname=studentname
        self.studentid=studentid
        self.booktime=booktime
        self.seatid=seatid
        self.width=width
        self.height=height

        # path=sys.argv[0]
        # path=path[0:path.rfind("/")]
        self.ordersucctitlepath="./gallery/order_succ_title.png"
        self.icopath="./gallery/icon.ico"

        # 字体标签
        title_qf=qfont()
        title_qf.setpointsize(11)
        title_qf.setbold(true)
        title_qf.setfamily("cambria")
        inf_qf=qfont()
        inf_qf.setpointsize(10)
        inf_qf.setbold(true)
        inf_qf.setfamily("cambria")
        matters_qf=qfont()
        matters_qf.setpointsize(10.5)
        matters_qf.setbold(true)
        matters_qf.setfamily("cambria")
        # ---
        self.qf_part_title=title_qf         # 框标题字体标签
        self.qf_inf_title=title_qf          # 信息标题字体标签
        self.qf_inf_text=inf_qf             # 信息文本字体标签
        self.qf_matters=matters_qf          # 注意事项字体标签

        # 样式表
        self.ss_part_frame="qlabel{background: rgb(245,245,245);color:rgb(92,92,92);border-radius:8px;border: 2.5px solid rgb(122,122,122)}"
        self.ss_part_title="qlabel{background: rgb(245,245,245);color:rgb(92,92,92)}"
        self.ss_inf_title="qlabel{background: rgb(230,230,230);color:rgb(82,82,82);border-radius:8px}"
        self.ss_text_line="qlabel{border-radius:3px;background: rgb(205,205,205);color:rgb(82,82,82)}"
        self.ss_book_btn="color:rgb(255,255,255);background: rgb(79,148,204)"

        self.setsize()
        self.seticon()
        self.settitle()
        self.partition()
        self.infdisplay()
        self.mattersdisplay()
        self.setbtn()
    # ================================================================================================
    # 回调函数部分:
    def templeave(self):
        if self.tleavebtn.text()=="暂离":
            setstring(self.seatid,"temp")
            nowdate=datetime.datetime.now()
            nowdatestr=nowdate.strftime('%y-%m-%d %h:%m:%s')
            self.infbox_time.settext(nowdatestr) 
            self.tleavebtn.settext("暂离中")

    def leave(self):
        freeseat(self.seatid)
        self.close()



    # ================================================================================================
    # 框架构造函数部分:
    def setsize(self):# 调整框架大小
        self.setgeometry(80,80,self.width,self.height)
        self.setmaximumsize(self.width,self.height)
        self.setminimumsize(self.width,self.height)

    def seticon(self):# 设置图标
        appicon=qicon(self.icopath)
        self.setwindowicon(appicon)

    def settitle(self):
        width=self.width
        height=self.height
        self.imgbox=qlabel(self)
        self.imgbox.setgeometry(0.24*width,0.02*height,
                                0.52*width,0.18*height)
        self.imgpic=qpixmap(self.ordersucctitlepath)
        self.imgpic=self.imgpic.scaled(0.52*width,0.18*height)
        self.imgbox.setpixmap(self.imgpic)

    def partition(self):# 绘制框线分布
        width=self.width
        height=self.height
        # ---信息展示框-----------------------------------------------
        self.part1=qlabel(self)
        self.part1.setgeometry(0.04*width,0.23*height,
                               0.92*width,0.40*height)
        self.part1.setstylesheet(self.ss_part_frame)
        self.part1title=qlabel(self)
        self.part1title.setgeometry(0.08*width,0.21*height,
                                    0.15*width,0.04*height)
        self.part1title.setstylesheet(self.ss_part_title)
        self.part1title.settext(" 个人信息 ")
        self.part1title.setfont(self.qf_part_title)
        # ---注意事项框-----------------------------------------------
        self.part2=qlabel(self)
        self.part2.setgeometry(0.04*width,0.67*height,
                               0.92*width,0.22*height)
        self.part2.setstylesheet(self.ss_part_frame)
        self.part2title=qlabel(self)
        self.part2title.setgeometry(0.08*width,0.65*height,
                                    0.15*width,0.04*height)
        self.part2title.setstylesheet(self.ss_part_title)
        self.part2title.settext(" 注意事项")
        self.part2title.setfont(self.qf_part_title)

    def infdisplay(self):
        width=self.width
        height=self.height
        # ---信息标题------------------------------------------
        self.inftitle_name=qlabel(self)
        self.inftitle_name.setgeometry(0.09*width,0.28*height,
                                       0.16*width,0.05*height)
        self.inftitle_name.setstylesheet(self.ss_inf_title)
        self.inftitle_name.settext("   姓名:")
        self.inftitle_name.setfont(self.qf_inf_title)
        # ---
        self.inftitle_id=qlabel(self)
        self.inftitle_id.setgeometry(0.09*width,0.36*height,
                                     0.16*width,0.05*height)
        self.inftitle_id.setstylesheet(self.ss_inf_title)
        self.inftitle_id.settext("   学号:")
        self.inftitle_id.setfont(self.qf_inf_title)
        # ---
        self.inftitle_time=qlabel(self)
        self.inftitle_time.setgeometry(0.09*width,0.44*height,
                                     0.16*width,0.05*height)
        self.inftitle_time.setstylesheet(self.ss_inf_title)
        self.inftitle_time.settext("   时间:")
        self.inftitle_time.setfont(self.qf_inf_title)
        # ---
        self.inftitle_seat=qlabel(self)
        self.inftitle_seat.setgeometry(0.09*width,0.52*height,
                                     0.16*width,0.05*height)
        self.inftitle_seat.setstylesheet(self.ss_inf_title)
        self.inftitle_seat.settext("   座次:")
        self.inftitle_seat.setfont(self.qf_inf_title)

        # ---信息文本框------------------------------------------
        self.infbox_name=qlabel(self) 
        self.infbox_name.settext(self.studentname) 
        self.infbox_name.move(0.3*width,0.281*height)  
        self.infbox_name.resize(0.6*width,0.048*height)
        self.infbox_name.setfont(self.qf_inf_text)
        self.infbox_name.setstylesheet(self.ss_text_line)
        self.infbox_name.setalignment(qt.aligncenter)
        # ---
        self.infbox_id=qlabel(self) 
        self.infbox_id.settext(self.studentid) 
        self.infbox_id.move(0.3*width,0.361*height)  
        self.infbox_id.resize(0.6*width,0.048*height)
        self.infbox_id.setfont(self.qf_inf_text)
        self.infbox_id.setstylesheet(self.ss_text_line)
        self.infbox_id.setalignment(qt.aligncenter)
        # ---
        self.infbox_time=qlabel(self) 
        self.infbox_time.settext(self.booktime) 
        self.infbox_time.move(0.3*width,0.441*height)  
        self.infbox_time.resize(0.6*width,0.048*height)
        self.infbox_time.setfont(self.qf_inf_text)
        self.infbox_time.setstylesheet(self.ss_text_line)
        self.infbox_time.setalignment(qt.aligncenter)
        # ---
        self.infbox_seat=qlabel(self) 
        self.infbox_seat.settext(self.seatid) 
        self.infbox_seat.move(0.3*width,0.521*height)  
        self.infbox_seat.resize(0.6*width,0.048*height)
        self.infbox_seat.setfont(self.qf_inf_text)
        self.infbox_seat.setstylesheet(self.ss_text_line)
        self.infbox_seat.setalignment(qt.aligncenter)

    def mattersdisplay(self):
        width=self.width
        height=self.height
        self.m1=qlabel(self) 
        self.m1.settext("1、预约成功后请在30分钟内到达,否则预约信息将失效。") 
        self.m1.setgeometry(0.06*width,0.71*height,
                            0.87*width,0.03*height)
        self.m1.setstylesheet("qlabel{color:rgb(82,82,82)}")
        self.m1.setfont(self.qf_matters)

        self.m2=qlabel(self) 
        self.m2.settext("2、进入自习室前请刷校园卡核验信息。") 
        self.m2.setgeometry(0.06*width,0.75*height,
                            0.87*width,0.03*height)
        self.m2.setstylesheet("qlabel{color:rgb(82,82,82)}")
        self.m2.setfont(self.qf_matters)

        self.m3=qlabel(self) 
        self.m3.settext("3、如要离开请点击下方“暂离”按钮,否则将释放座位信息。") 
        self.m3.setgeometry(0.06*width,0.79*height,
                            0.87*width,0.03*height)
        self.m3.setstylesheet("qlabel{color:rgb(82,82,82)}")
        self.m3.setfont(self.qf_matters)

        self.m4=qlabel(self) 
        self.m4.settext("4、离开、取消预约请点击下方“离开\取消”按钮。") 
        self.m4.setgeometry(0.06*width,0.83*height,
                            0.87*width,0.03*height)
        self.m4.setstylesheet("qlabel{color:rgb(82,82,82)}")
        self.m4.setfont(self.qf_matters)

    def setbtn(self):
        width=self.width
        height=self.height
        self.tleavebtn=qpushbutton(self)
        self.tleavebtn.setgeometry(0.18*width,(0.92)*height,0.2*width,0.05*height)
        self.tleavebtn.setstylesheet(self.ss_book_btn)
        self.tleavebtn.settext("暂离")
        self.tleavebtn.setfont(self.qf_inf_title)
        self.tleavebtn.clicked.connect(self.templeave)

        width=self.width
        height=self.height
        self.leavebtn=qpushbutton(self)
        self.leavebtn.setgeometry((1-0.2-0.18)*width,(0.92)*height,0.2*width,0.05*height)
        self.leavebtn.setstylesheet(self.ss_book_btn)
        self.leavebtn.settext("离开\取消")
        self.leavebtn.setfont(self.qf_inf_title)
        self.leavebtn.clicked.connect(self.leave)

# ===========================================================================================
# 函数调用:
# myapp = qapplication(sys.argv)
# window_disp = window_disp("李华","1816000xxxx","2021-05-30 17:04:24","a1",700,840)
# window_disp.show()
# myapp.exec_()


def orderdisplay(studentname,studentid,booktime,seatid,width=700,height=840):
    window_disp = window_disp(studentname,studentid,booktime,seatid,width,height)
    return window_disp

-1 后注

完整代码、json文件、图片素材、md文件下载链接如下,详细描述请阅读readme.md文件:

到此这篇关于python实现简易自习室座位预约系统的文章就介绍到这了,更多相关python自习室座位预约内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!