当所有其他方法都失败时,尝试阅读文档(即,如果有的话;-)。
使用 EasyGui,虽然是单独下载,但该网页easygui-docs-0.97.zip
上显示的文件。以下是该函数的 API 部分中的说明:integerbox()
所以,要回答你的问题,不,似乎没有办法禁用模块的边界检查integerbox()
。
更新:这是一个你可以添加到模块中的新函数,它根本不做边界检查,也不接受边界参数(因此它与股票版本不严格调用兼容)。如果您将其放入,请务必将其名称 , 添加到模块脚本文件顶部附近的列表'integerbox2'
定义中。__all__
如果您想尽量减少对easygui
模块脚本本身的更改,以防将来有更新,您可以将新函数放在单独的.py
文件中,然后import integerbox2
在顶部附近添加一个easygui.py
(加上另一行将其添加到__all__
)。
这是附加功能:
#-------------------------------------------------------------------
# integerbox2 - like integerbox(), but without bounds checking.
#-------------------------------------------------------------------
def integerbox2(msg=""
, title=" "
, default=""
, image=None
, root=None):
"""
Show a box in which a user can enter an integer.
In addition to arguments for msg and title, this function accepts
an integer argument for "default".
The default argument may be None.
When the user enters some text, the text is checked to verify that it
can be converted to an integer, **no bounds checking is done**.
If it can be, the integer (not the text) is returned.
If it cannot, then an error msg is displayed, and the integerbox is
redisplayed.
If the user cancels the operation, None is returned.
:param str msg: the msg to be displayed
:param str title: the window title
:param str default: The default value to return
:param str image: Filename of image to display
:param tk_widget root: Top-level Tk widget
:return: the integer value entered by the user
"""
if not msg:
msg = "Enter an integer value"
# Validate the arguments and convert to integers
exception_string = ('integerbox "{0}" must be an integer. '
'It is >{1}< of type {2}')
if default:
try:
default=int(default)
except ValueError:
raise ValueError(exception_string.format('default', default,
type(default)))
while 1:
reply = enterbox(msg, title, str(default), image=image, root=root)
if reply is None:
return None
try:
reply = int(reply)
except:
msgbox('The value that you entered:\n\t"{}"\n'
'is not an integer.'.format(reply), "Error")
continue
# reply has passed validation check, it is an integer.
return reply