界面生成
import ttkbootstrap as ttk from vehicleIdentificationNumber import vin_numbers, get_normal_vin, check_vin class Vin9Frame(ttk.Frame): def __init__(self, container): super().__init__(container) self.container = container # field options self.count = 10 options = {'padx': 2, 'pady': 0} self.initFrame() self.textEntry.set(10) # 布局 def initFrame(self): labFrame = ttk.LabelFrame(self.container, text="Vin Data Validation") # 创建框架标签 # self.initCheck(labFrame) self.initGenerVin(labFrame) labFrame.pack(padx=2, pady=10, ipadx=2, ipady=2) self.initText(labFrame) def initCheck(self, labFrame): self.vintextL = ttk.StringVar() self.vintextL.set("vin:") self.vinL = ttk.Label(labFrame, text="vin:", textvariable=self.vintextL) self.vinL.grid(row=0, column=0) self.vintext = ttk.StringVar() self.vin = ttk.Entry(labFrame, width=17, textvariable=self.vintext) self.vin.grid(row=0, column=1) self.vin.bind('<Key>', lambda e: self.TextChange(e, self.vintext)) # 给输入框绑定键盘敲击事件,把绑定的变量传入回调函数中 # 设置文本框只能输入数字 self.vin.config(validate="key", validatecommand=(self.container.register(lambda P: P.isascii()), "%P")) btn = ttk.Button(labFrame, text="Check", command=self.checkCallBack) btn.grid(row=0, column=2) self.isRulesVin = ttk.Entry(labFrame, style=ttk.PRIMARY, width=10, state='readonly') self.isRulesVin.grid(row=0, column=3) def initGenerVin(self, labFrame): numberL = ttk.Label(labFrame, text="vin nums:") numberL.grid(row=1, column=0) self.textEntry = ttk.StringVar() self.number = ttk.Entry(labFrame, textvariable=self.textEntry, width=15) self.number.grid(row=1, column=1) # 设置文本框只能输入数字 self.number.config(validate="key", validatecommand=(self.container.register(lambda P: P.isdigit()), "%P")) generBtn = ttk.Button(labFrame, text="Gener", command=self.generBtnCallBack) generBtn.grid(row=1, column=2) generBtn = ttk.Button(labFrame, text="G-One", command=self.generOneBtnCallBack) generBtn.grid(row=1, column=3) def initText(self, labFrame): scrollbar_v = ttk.Scrollbar(self.container) scrollbar_v.pack(side=ttk.RIGHT, fill=ttk.Y) scrollbar_h = ttk.Scrollbar(self.container, orient=ttk.HORIZONTAL) scrollbar_h.pack(side=ttk.BOTTOM, fill=ttk.X) self.text1 = ttk.Text(self.container, yscrollcommand=scrollbar_v.set, xscrollcommand=scrollbar_h.set, wrap=ttk.NONE) self.text1.pack(expand=ttk.YES, fill=ttk.BOTH) scrollbar_v.config(command=self.text1.yview) # 垂直滚动条绑定text scrollbar_h.config(command=self.text1.xview) # 水平滚动条绑定text def checkCallBack(self): if (self.vin.get()): self.vintextL.set('vin: ' + str(len(self.vin.get()))) self.isRulesVin.config(state='normal') self.isRulesVin.delete(0, ttk.END) msg = check_vin(self.vin.get()) self.isRulesVin.insert(ttk.END, msg if msg.find('-') == -1 else msg[msg.find('-') + 1:]) self.isRulesVin.config(state='readonly') self.text1.insert(ttk.END, msg + "\n") def generBtnCallBack(self): if (self.number.get()): self.text1.delete(1.0, ttk.END) vins = vin_numbers(int(self.number.get())) for vin in vins: self.text1.insert(ttk.END, vin + "\n") def generOneBtnCallBack(self): self.text1.delete(1.0, ttk.END) self.text1.insert(ttk.END, get_normal_vin()) # END实际就是字符串'end' def TextChange(self, event, widgetVar): self.vintextL.set('vin: ' + str(len(self.vin.get())))
规则源码
# -*-coding:utf-8-*- ''' VIN 规则算法部分 ''' import random import string import pandas as pd lists = { "A": 1, "B": 2, "C": 3, "D": 4, "E": 5, "F": 6, "G": 7, "H": 8, "J": 1, "K": 2, "L": 3, "M": 4, "N": 5, "P": 7, "R": 9, "S": 2, "T": 3, "U": 4, "V": 5, "W": 6, "X": 7, "Y": 8, "Z": 9, "0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, } df = pd.DataFrame(lists, index=[0])#变成dataframe类型,打印结果如下效果 # A B C D E F G H J K L M N ... X Y Z 0 1 2 3 4 5 6 7 8 9 #0 1 2 3 4 5 6 7 8 1 2 3 4 5 ... 7 8 9 0 1 2 3 4 5 6 7 8 9 def check_vin(text): if len(text) == 17:#判断它是否为17位数 text = text.upper()#小写字母转化为大写字母 text1 = text.replace("Q","0").replace("O","0").replace("I","1")#替换文本中的字母 if(text.find("Q") != -1 or text.find("O") != -1 or text.find("I") != -1): return "含有QOI-不符合规范" Nums = bitWeight(text1) # 如果余数是10 则是X try: if (''.join(text1[8]).isdigit() or ''.join(text1[8]).upper() == 'X'): # 如果余数是10 则是X return "符合规范" if Nums % 11 == (10 if (Nums % 11 == 10) else int(text1[8])) else "不符合规范" else: return '不符合规范' except Exception as e: return e.__str__()+'-不符合规范' else: return "长度不是17位数-不符合规范" def generate_random_string(length): # 生成包含大小写字母和数字的序列 characters = string.ascii_uppercase.replace('Q', '').replace('I', '').replace('O', '') + string.digits # 随机选择 length 个字符 return ''.join(random.choice(characters) for i in range(length)) def getPostion(text): positions = [] for i in range(17): if i != 8: positions.append(int(df[text[i]].to_string()[-1])) else: positions.append('X') return positions def bitWeight(text): pos = getPostion(text) posSum = 0 for i in range(17): if i < 7: posSum = posSum + pos[i]*(8 - i) elif i == 7: posSum = posSum + pos[i] * (i + 3) elif i == 8: # 不参与计算 pass else: posSum = posSum + int(pos[i]) * (9 - (i - 9)) return posSum def get_normal_vin(): strLeft = generate_random_string(8) strRight = generate_random_string(8) Nums = bitWeight(strLeft+'X'+strRight) # 如果余数是10 则是X str9 = 'X' if(Nums % 11 == 10) else ''.join(str(Nums % 11)) return strLeft+str9+strRight def get_normal_vin1(left, right): strLeft = left strRight = right Nums = bitWeight(strLeft+'X'+strRight) # 如果余数是10 则是X str9 = 'X' if(Nums % 11 == 10) else ''.join(str(Nums % 11)) return strLeft+str9+strRight def vin_numbers(number = 10): vins = [] for i in range(number): vins.append(get_normal_vin()) return vins
EXE执行程序:链接: https://pan.baidu.com/s/1rJ58TMrFkFROGqS5Tq9Trw 提取码: 49fy
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
· 全程使用 AI 从 0 到 1 写了个小工具