python3的wxpython界面模拟登录爬取教务系统实现查询系统功能2.0版本

前言

今天来补充之前的界面操作系统,为学生查询操作系统2.0版本,依旧是用wxpython来做一个可视化的操作界面,用的工具依然是selenium库,beautifulsoup4库,还有设计界面的wx,和表格wx.grid,后面两个只要下载wxpython库即可

首先是界面操作

里面的分别对应的文本,按钮,背景图片,图标都有标明

#继承wx库里面的Frame类来使用
class myFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, 'ZSC-学生查询系统', pos=(100, 100), size=(1400, 600))
        self.MaxSize = self.Size
        self.MinSize = self.Size
        panel = wx.Panel(self, -1)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer1 = wx.BoxSizer(wx.VERTICAL)
        sizer3 = wx.BoxSizer(wx.VERTICAL)
        font = wx.Font(15, wx.ROMAN, wx.NORMAL, wx.BOLD)

        #设置窗口以及托盘图标
        icon = wx.Icon()
        icon.CopyFromBitmap(wx.Bitmap(wx.Image(("E:\py\系统图片\zsc.jpg"), wx.BITMAP_TYPE_JPEG)))
        self.SetIcon(icon)

        #设置左边背景学院logo
        image = wx.Image("E:\py\系统图片\中山学院.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.background = wx.StaticBitmap(panel, -1, bitmap=image,style=wx.ALIGN_CENTER)
        sizer1.Add(self.background,proportion=10,flag= wx.ALIGN_CENTER_VERTICAL, border=10)

        #设置静态‘用户名'
        self.text1 = wx.StaticText(panel, -1, '用户名:', style=wx.ALIGN_CENTER)
        self.text1.SetFont(font)
        sizer1.Add(self.text1, proportion=2, flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=10)

        #用户名输入框
        self.text2 = wx.TextCtrl(panel, -1, size=(200, -1), style=wx.TE_LEFT)
        self.text2.SetFont(font)
        sizer1.Add(self.text2, proportion=0, flag=wx.ALIGN_CENTER | wx.EXPAND, border=15)

        #设置静态'密码'
        self.text3 = wx.StaticText(panel, -1, '密码:', style=wx.ALIGN_CENTER)
        self.text3.SetFont(font)
        sizer1.Add(self.text3, proportion=2, flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=10)

        #密码输入框
        self.text4 = wx.TextCtrl(panel, -1, size=(200, -1), style=wx.TE_LEFT|wx.TE_PASSWORD|wx.TE_PROCESS_ENTER)
        self.text4.SetFont(font)
        sizer1.Add(self.text4, proportion=0, flag=wx.ALIGN_CENTER | wx.EXPAND, border=15)

        # 设置获取成绩按钮
        self.command1 = wx.Button(panel, -1, '→获取个人成绩单')
        self.command1.SetFont(font)
        self.command1.SetBackgroundColour('#3299CC')
        sizer1.Add(self.command1, proportion=5, flag=wx.ALIGN_CENTER | wx.EXPAND, border=10)

        #设置获取课程表按钮
        self.command4 = wx.Button(panel, -1, '→获取个人课程表')
        self.command4.SetFont(font)
        self.command4.SetBackgroundColour('#DBDB70')
        sizer1.Add(self.command4, proportion=5, flag=wx.ALIGN_CENTER | wx.EXPAND, border=10)

        #设置获取素拓分按钮
        self.command3 = wx.Button(panel, -1, '→获取个人素拓分')
        self.command3.SetFont(font)
        self.command3.SetBackgroundColour('#32CC32')
        sizer1.Add(self.command3, proportion=5, flag=wx.ALIGN_CENTER | wx.EXPAND, border=10)

        #设置重置按钮
        self.command2 = wx.Button(panel, -1, '→重置输入框')
        self.command2.SetFont(font)
        self.command2.SetBackgroundColour((random.randint(1, 255), random.randint(0, 255), random.randint(0, 255)))
        sizer1.Add(self.command2, proportion=5, flag=wx.ALIGN_CENTER | wx.EXPAND, border=10)

        #设置消息提示文本
        self.text5 = wx.StaticText(panel, -1, '\n\n', style=wx.ALIGN_CENTER)
        self.text5.SetFont(font)
        self.text5.SetForegroundColour('Red')
        sizer1.Add(self.text5, proportion=15, flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=10)

        #设置个人信息文本
        self.text6 = wx.StaticText(panel, -1, '姓名:')
        self.text7 = wx.StaticText(panel, -1, '学号:')
        self.text8 = wx.StaticText(panel, -1, '学院:')
        sizer1.Add(self.text6, proportion=3, flag=wx.LEFT, border=0)
        sizer1.Add(self.text7, proportion=3, flag=wx.LEFT, border=0)
        sizer1.Add(self.text8, proportion=3, flag=wx.LEFT, border=0)

        #把分布局全部加入整体顶级布局
        sizer.Add(sizer1, flag=wx.EXPAND | wx.ALL, border=20)
        sizer.Add(sizer3, flag=wx.EXPAND | wx.ALL, border=20)
        self.grid = mygrid(panel)
        sizer.Add(self.grid, proportion=1, flag=wx.EXPAND | wx.ALL, border=25)

        self.grid.SetSize((200, 400))

        panel.SetSizer(sizer)

        #四个按钮对应的事件
        self.command1.Bind(wx.EVT_BUTTON, self.command1_event)
        self.command4.Bind(wx.EVT_BUTTON, self.command4_event)
        self.command3.Bind(wx.EVT_BUTTON, self.command3_event)
        self.command2.Bind(wx.EVT_BUTTON, self.command2_event)
        self.Show()

    def command1_event(self, event):
        self.text6.SetLabel('姓名:')
        self.text7.SetLabel('学号:')
        self.text8.SetLabel('学院:')
        self.grid.ff()
        self.grid.Update()
        self.text5.SetLabel(u'\n温馨提示:\n' + '⚪登录信息验证中...')
        self.text5.Update()
        try:
            name = self.text2.GetValue()
            password = self.text4.GetValue()
            courses = get_data_from_zsc1(name,password)
            if courses.result == False:
                self.text5.SetLabel(u'\n温馨提示:\n' + '×用户名或密码错误!' )
            else:
                student_course = courses.my_score_list
                self.text5.SetLabel(u'\n温馨提示:\n' + '√登录成功并获得成绩!')
                self.text6.SetLabel('姓名:' + courses.my_information[0])
                self.text7.SetLabel('学号:' + courses.my_information[1])
                self.text8.SetLabel('学院:' + courses.my_information[2] )
                try:
                    self.grid.header = grade
                    for i in range(len(self.grid.header)):
                        self.grid.SetColLabelValue(i, self.grid.header[i])
                    self.grid.Update()
                    self.grid.Refresh()
                except:
                    pass
                n1 = len(student_course)
                n2 = len(student_course[0])
                self.grid.InsertRows(0, n1)
                for i in range(0, n1):
                    for j in range(0, n2):
                        self.grid.SetCellValue(i, j, student_course[i][j])
                #self.grid.AutoSize() #自动调整单元格大小
        except:
            self.Message = wx.MessageDialog(self, '账号或密码不能为空!', 'ERROR',wx.ICON_ERROR)
            self.Message.ShowModal()
            self.Message.Destroy()

    def command4_event(self, event):
        self.text6.SetLabel('姓名:')
        self.text7.SetLabel('学号:')
        self.text8.SetLabel('学院:')
        self.grid.ff()
        self.grid.Update()
        self.text5.SetLabel(u'\n温馨提示:\n' + '⚪登录信息验证中...')
        self.text5.Update()
        try:
            name = self.text2.GetValue()
            password = self.text4.GetValue()
            courses = get_data_from_zsc2(name,password)
            if courses.result == False:
                self.text5.SetLabel(u'\n温馨提示:\n' + '×用户名或密码错误!' )
            else:
                student_timetable = courses.all_data
                self.text5.SetLabel(u'\n温馨提示:\n' + '√登录成功并获得课程表!')
                self.text6.SetLabel('姓名:' + courses.my_information[0])
                self.text7.SetLabel('学号:' + courses.my_information[1])
                self.text8.
  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值