Python EasyGUI – Integer Box
Last Updated :
12 Apr, 2023
Integer Box : It is used to get the integer input from the user, input should be integer input not string which happens in enter box. It displays the title, message to be displayed, place to enter a integer input and a pair of “Ok”, “Cancel” button which is used confirm the input. We can set some default integer value to the place where user enter text and we can also set lower and upper bound value which user can enter, below is how the enter box looks like
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
Example : In this we will create a integer box with default integer and with lower and upper bound value, and will show the specific message on the screen according to the entered integer, below is the implementation
Python3
from easygui import *
text = "Enter Something (integer)"
title = "Window Title GfG"
d_int = 10
lower = 0
upper = 99999
output = integerbox(text, title, d_int, lower, upper)
title = "Message Box"
message = "Entered Number : " + str (output)
msg = msgbox(message, title)
|
Output :
Another Example : In this we will create a integer box and will show the specific message on the screen according to the entered integer, below is the implementation
Python3
from easygui import *
text = "Enter a number !!"
title = "Window Title GfG"
output = integerbox(text, title)
title = "Message Box"
message = "Entered Number : " + str (output)
msg = msgbox(message, title)
|
Output :
If we try to enter wrong input i.e string or number which don’t lie between the specified lower and upper bound an error message will keep appearing until correct input is entered
Share your thoughts in the comments
Please Login to comment...