Python结合wxPython实现身份证更新换代、显示基本公民信息软件

时间:2020-12-18 07:11:31

这个程序有些许的BUG,因为没时间所以就不改正了。

# -*- coding: utf-8 -*-

###########################################################################
## Python code generated with wxFormBuilder (version Feb 16 2016)
## http://www.wxformbuilder.org/
##
## PLEASE DO "NOT" EDIT THIS FILE!
###########################################################################

import wx
import wx.xrc


###########################################################################
## Class MyFrame2
###########################################################################

class MyFrame2(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString, pos=wx.DefaultPosition,
                          size=wx.Size(683, 343), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)

        self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)

        bSizer5 = wx.BoxSizer(wx.VERTICAL)

        bSizer6 = wx.BoxSizer(wx.HORIZONTAL)

        self.m_staticText2 = wx.StaticText(self, wx.ID_ANY, u" 请输入原身份证号", wx.Point(120, 120), wx.Size(160, 40), 0)
        self.m_staticText2.Wrap(-1)
        bSizer6.Add(self.m_staticText2, 0, wx.ALL, 5)

        self.m_textCtrl6 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size(400, 40), 0)
        bSizer6.Add(self.m_textCtrl6, 0, wx.ALL, 5)

        bSizer5.Add(bSizer6, 0, wx.EXPAND, 5)

        bSizer7 = wx.BoxSizer(wx.HORIZONTAL)

        self.m_staticText3 = wx.StaticText(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size(300, 40), 0)
        self.m_staticText3.Wrap(-1)
        bSizer7.Add(self.m_staticText3, 0, wx.ALL, 5)

        self.m_button9 = wx.Button(self, wx.ID_ANY, u"转换", wx.DefaultPosition, wx.Size(110, 40), 0)
        bSizer7.Add(self.m_button9, 0, wx.ALL, 5)

        bSizer5.Add(bSizer7, 0, wx.EXPAND, 5)

        bSizer10 = wx.BoxSizer(wx.HORIZONTAL)

        self.m_staticText6 = wx.StaticText(self, wx.ID_ANY, u"原来身份证为:", wx.DefaultPosition, wx.Size(100, 40), 0)
        self.m_staticText6.Wrap(-1)
        bSizer10.Add(self.m_staticText6, 0, wx.ALL, 5)

        self.m_textCtrl8 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size(450, 40), 0)
        bSizer10.Add(self.m_textCtrl8, 0, wx.ALL, 5)

        bSizer5.Add(bSizer10, 0, wx.EXPAND, 5)

        bSizer11 = wx.BoxSizer(wx.HORIZONTAL)

        self.m_staticText7 = wx.StaticText(self, wx.ID_ANY, u"现在身份证为:", wx.DefaultPosition, wx.Size(120, 40), 0)
        self.m_staticText7.Wrap(-1)
        bSizer11.Add(self.m_staticText7, 0, wx.ALL, 5)

        self.m_textCtrl9 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size(500, 40), 0)
        bSizer11.Add(self.m_textCtrl9, 0, wx.ALL, 5)

        bSizer5.Add(bSizer11, 0, wx.EXPAND, 5)

        bSizer12 = wx.BoxSizer(wx.HORIZONTAL)

        self.m_staticText8 = wx.StaticText(self, wx.ID_ANY, u"出生日期为:", wx.DefaultPosition, wx.Size(120, 40), 0)
        self.m_staticText8.Wrap(-1)
        bSizer12.Add(self.m_staticText8, 0, wx.ALL, 5)

        self.m_textCtrl10 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.Point(-1, -1), wx.Size(300, 40), 0)
        bSizer12.Add(self.m_textCtrl10, 0, wx.ALL, 5)

        bSizer5.Add(bSizer12, 0, wx.EXPAND, 5)

        bSizer13 = wx.BoxSizer(wx.HORIZONTAL)

        self.m_staticText9 = wx.StaticText(self, wx.ID_ANY, u" 性别为:", wx.DefaultPosition, wx.Size(110, 40), 0)
        self.m_staticText9.Wrap(-1)
        bSizer13.Add(self.m_staticText9, 0, wx.ALL, 5)

        self.m_textCtrl11 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size(-1, 40), 0)
        bSizer13.Add(self.m_textCtrl11, 0, wx.ALL, 5)

        bSizer5.Add(bSizer13, 1, wx.EXPAND, 5)

        self.SetSizer(bSizer5)
        self.Layout()

        self.Centre(wx.BOTH)

        # Connect Events
        self.m_button9.Bind(wx.EVT_BUTTON, self.m_button9OnButtonClick)

    def __del__(self):
        pass

    # Virtual event handlers, overide them in your derived class
    def m_button9OnButtonClick(self, event):
        Id=str(self.m_textCtrl6.GetValue())
        for i,j in enumerate(Id):
            if(j>'9' or j<'0'):
                self.m_textCtrl6.SetValue(u"身份证输入错误!")

        #添加19
        biaozhun="32032419980521091"

        final_list=[2,4,8,5,10,9,7,3,6,1,2,4,8,5,10,9,7]
        final_num=0
        for p,q in enumerate(final_list):
            final_num+=int(final_list[q]*int(biaozhun[q]))
        final_num%=11
        final=('1','0','X','3','4','5','6','7','8','9','2')
        biaozhun+=final[final_num]

        date=biaozhun[6:14]
        sex=u"男"
        if(int(biaozhun[16])%2==0):
            sex=u"女"
        else:
            sex=u"男"
        self.m_textCtrl9.SetValue(biaozhun)
        self.m_textCtrl8.SetValue(str(Id))
        self.m_textCtrl10.SetValue(date)
        self.m_textCtrl11.SetValue(sex)
app=wx.App()
window=MyFrame2(None)
window.Show(True)
app.MainLoop()