方便的数据输入和验证。

easyentr的Python项目详细描述


概述

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

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

  • type:str、int、float、date、time、email、passwd和menu。
  • default:按回车键设置默认值
  • options:定义允许值的列表:['a','b',…]
  • <值:设置一个值的最小和最大限制:[ 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:with true返回所选选项的编号
  • sorted:排序选项列表(true/false)

输出:

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:必需,options或minmax和default
  • int:必需,options或minmax和default
  • float:必需,options或minmax和default
  • date:必需,选项或mixmax,默认值:date或now
  • time:必需,选项或mixmax,默认值:time或now
  • 密码:必需的
  • email:必需的
  • menu:必需,标题,选项,默认值,排序和索引

常数

常数用于设置定义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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Gradle嵌套项目配置   java一些mipmap没有显示   java如何使用按钮设置值以在wicket中输入文本   可分页的java自定义排序参数   java Android AdMob NoSuchMethodError:没有静态方法zzand()   java安卓工作室;启动到USB设备(手机),已安装但无法打开   java如何使用jsoup从HTML解析表   java如何自动生成arraylist?   java定制外观和感觉Nimbus   在Java中使用气泡排序对24位数组进行排序   java我无法将javafx与spring集成   java Play 2.7 http请求post请求   Java哈希表在“put”期间用新密钥覆盖现有密钥   如何找到java更新版本?