Open In App

Python EasyGUI – Integer Box

Improve
Improve
Like Article
Like
Save
Share
Report

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




# 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 = "Entered Number : " + str(output)
 
# creating a message box
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




# 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 = "Entered Number : " + str(output)
 
# creating a message box
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



Last Updated : 12 Apr, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads