在 wxPython 中验证数据 [英] Validating data in wxPython

查看:23
本文介绍了在 wxPython 中验证数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为表单上的输入创建验证器.我已经了解到,在 wxPython 中,由于缺乏对标准 wxTextValidator 等的支持,必须从 wx.Validator 继承.

I'm trying to create Validators for inputs on forms. I learned already that in wxPython it is necessary to inherit from wx.Validator due to lack of support for standard wxTextValidator and others.

我的问题是:

  • 如何有效地检查字符串是否符合简单规则(请不要使用正则表达式)

  • how effectively check that string complies to simple rules (no regexp please)

acceptableChars = ['a', 'b', ...]

all(char inacceptableChars for char in string)

这样的东西有效率吗?以及如何干净地指定所有字母数字或数字?或者有没有现成的类或函数?

is something like this efficient? and how to cleanly specify all alphanumeric or digits? or maybe is there any ready class or function?

将覆盖 Validate 方法仅在输入数据时保留约束 - 我的意思是它会阻止用户将数字输入字母数字 TextCtrl 还是只会在关闭模态对话框?

will overriding Validate method only keep the constraints while inputing data - I mean will it prevent user from entering digits into alphanumerical TextCtrl or will it check only at closing the modal diagog?

推荐答案

Validate() 仅在对话框默认即将关闭时调用,但您也可以在控件关闭时自己调用失去焦点.最后,如果您的控件根本不接受某些字符,您还可以拦截 wxEVT_CHAR 事件以防止它们被输入.我相信 wxPython 演示展示了如何做到这一点.

Validate() is called only when the dialog is about to close by default, but you may also call it yourself when the control loses focus. Finally, if your control doesn't accept some characters at all, you can also intercept wxEVT_CHAR events to prevent them from being entered. I do believe wxPython demo shows how to do it.

这篇关于在 wxPython 中验证数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆