Skip to content
Related Articles

Related Articles

Improve Article
Python EasyGUI – Integer Box
  • Last Updated : 05 Sep, 2020

Integer Box : It is used to get the integer input from the user, input should be integer input not sting 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




# 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)

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




# 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)

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

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :