Skip to main content

轻松的数据输入和验证。

项目描述

概述

EasyEntry 将数据输入程序并轻松检查它们是否有效。

使用字典来定义数据的属性:

  • 类型:str、int、float、日期、时间、电子邮件、密码和菜单。

  • 默认值:按回车键设置默认值

  • options : 定义允许值的列表:['a', 'b',...]

  • minmax:设置值的最小和最大限制:[0, 100]

  • required : 定义引入值的义务或不引入值:True 或 False

  • 和其他(见物业清单)。

例子:

import easyentry as ee

ee.global_required = True

person = {}
person['name'] = {'type':'str'}
person['city'] = {'type':'str', 'default':'Seville'}
person['age']  = {'type':'int', 'minmax': [0,100]}
person['height']  = {'type':'float'}
person['bicycle']  = {'type':'str', 'options': ['y','n']}
person['datetrip'] = {'type':'date', 'default': 'now'}
person['email'] = {'type':'email', 'required': False}

name = ee.entry('What is your name?', (person, 'name'))
city = ee.entry('What city you live?', (person, 'city'))
age = ee.entry('How old are you?', (person, 'age'))
height = ee.entry('Height?', (person, 'height'))
bicycle = ee.entry('Do you have a bicycle?', (person, 'bicycle'))
datetrip = ee.entry('Date of trip?', (person, 'datetrip'))
email = ee.entry('Your email address', (person, 'email'))

创建一个选项菜单

要构建菜单:

person['info'] = {'type':'menu', 'title':'Select an option', 'options':['phone','mail','none'], 'rindex':True}
info = ee.entry('To receive information by...', (person, 'info'))

选项:

  • rindex : True 返回所选选项的编号

  • sorted:对选项列表进行排序(真/假)

输出:

To receive information by...
(1) phone
(2) mail
(3) none
Select an option [3]:

密码

输入密码:

person['passwd'] = {'type':'passwd'}

passwd = ee.entry('Enter password', (person, 'passwd'))
repeat = ee.entry('Repeat password', (person, 'passwd'))

if passwd == repeat:
    print(passwd)

物业清单

可用数据类型的属性:

  • str:必需,选项或 minmax 和默认值

  • int:必需,选项或 minmax 和默认值

  • float:必需,选项或 minmax 和默认值

  • 日期:必需,选项或 mixmax 和默认值:日期或现在

  • 时间:必需,选项或 mixmax 和默认值:时间或现在

  • 密码:必填

  • 电子邮件:必填

  • 菜单:必需、标题、选项、默认、排序和 rindex

常数

常量用于设置定义 EasyEntry 的一般行为的值:

# Message to be displayed when data is not valid:
# - You can type the message in your language
# - If the value is omitted, the default is the current (in English)

ee.error_message = 'Invalid input, please try again'

# Set format 'date' and 'time':
# - Date format: '%Y-%m-%d' -> YYYY-MM-DD (default)
# - Hour format: '%H:%M:%S' -> HH:MM:SS   (default)

ee.date_format = '%d-%m-%Y'
ee.time_format = '%H:%M'

# Set the type of numerical data (int and float):
# - True and value = '' : var int   -> return 0
#                         var float -> return 0.0
# - False (default) and value = '': return ''

ee.strict_return = False

# Establish whether it is mandatory to enter a valid value or
# an empty entry (press return) is allowed
# - True  -> You must enter a valid value in all fields
# - False -> The field can be empty (default)
# The value of the 'required' property of a field overrides
# the global value

ee.global_required = True

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

easyentry-0.0.9.tar.gz (19.6 kB 查看哈希

已上传 source

内置分布

easyentry-0.0.9-py2.py3-none-any.whl (9.5 kB 查看哈希

已上传 py2 py3