我使用EasyGUI作为一个小程序,我写的一部分。 在这里面,我现在用的是IntegerBox“功能”。
这个函数中的参数的一部分是下界和上界(所述值的限制输入)。 如果该值是下界下,或者如果它超过上界,该程序引发错误。
只有这个程序,我想删除下界/上界---这样就可以把任何号码。
我的代码是:
import easygui as eg
numMin=eg.integerbox(msg="What is the minimum value of the numbers?"
, title="Random Number Generator"
, default=0
, lowerbound=
, upperbound=
, image=None
, root=None
)
我没有任何东西进入,但因为我不知道要放什么东西。 任何投入将不胜感激。 谢谢!
当一切都失败了,尝试阅读文档(即,如果有任何;-)。
随着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