Python EasyGUI - 整数框
Integer Box :用于获取用户输入的整数,输入应该是整数输入,而不是在输入框中发生的sting。它显示标题、要显示的消息、输入整数输入的位置和一对“确定”、“取消”按钮,用于确认输入。我们可以在用户输入文本的地方设置一些默认的整数值,我们也可以设置用户可以输入的下限和上限,下面是输入框的样子
In order to do this we will use integerbox
method
Syntax : integerbox(message, title, default_integer, lower_bound, upper_bound)
Argument : It takes 5 arguments, first string i.e message/information to be displayed, second string i.e title of the window, third is integer which is default integer, forth and fifth are integer representing lower and upper bound respectively
Return : It returns the entered integer and None if cancel is pressed
例子 :
在此我们将创建一个具有默认整数和上下界值的整数框,并将根据输入的整数在屏幕上显示特定的消息,下面是实现
# importing easygui module
from easygui import *
# message to be displayed
text = "Enter Something (integer)"
# window title
title = "Window Title GfG"
# default integer
d_int = 10
# lower bound
lower = 0
# upper bound
upper = 99999
# creating a integer box
output = integerbox(text, title, d_int, lower, upper)
# title for the message box
title = "Message Box"
# creating a message
message = "Enterted Number : " + str(output)
# creating a message box
msg = msgbox(message, title)
输出 :
另一个例子 :
在此我们将创建一个整数框,并根据输入的整数在屏幕上显示特定的消息,下面是实现
# importing easygui module
from easygui import *
# message to be displayed
text = "Enter a number !!"
# window title
title = "Window Title GfG"
# creating a integer box
output = integerbox(text, title)
# title for the message box
title = "Message Box"
# creating a message
message = "Enterted Number : " + str(output)
# creating a message box
msg = msgbox(message, title)
输出 :
如果我们尝试输入错误的输入,即不位于指定下限和上限之间的字符串或数字,则会一直出现错误消息,直到输入正确的输入