⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 validation.py

📁 Python.Tkinter编程实例代码多多学习
💻 PY
字号:
from tkMessageBox import *
import string

def validIP(value):
    valid = 0
    try:
        if len(value) >=7 and len(value) <= 15:
            fields = string.splitfields(value, '.')
            if len(fields) < 5:
                for field in fields:
                    iV = string.atoi(field)
                    if iV < 0 or iV > 255:
                        valid = 0
                        break
                    else:
                        valid = 1
    except:
        pass
    if not valid:
        showerror(title='Invalid IP Address',
                  message='Format: nnn.nnn.nnn.nnn\n-1 < nnn < 256')
    return (value, 0, valid)

def validCP(value):
    valid = 0
    try:
        fields = string.splitfields(value, '-')
        for field in fields:
            iV = string.atoi(field)
            if iV < 1 or iV > 100:
                valid = 0
                break
            else:
                valid = 1
    except:
        pass
    if not valid:
        showerror(title='Invalid Card-Port',
                  message='Format: nnn-nnn\n0 < nnn < 101'),
    return (value, 0, valid)

def validLName(value):
    valid = 0
    try:
        if len(value) >= 3:
            ucFTC = string.upper(value[:2])
            if ucFTC == 'CP':
                valid = 1
    except:
        pass
    if valid:
        retval = 'CP' + value[2:]
        replace = 1
    else:
        showerror(title='Invalid Logical Name',
                  message='Format: CP+<text>')
        retval = value
        replace = 0
    return (retval, replace, valid)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -