Open In App

Python EasyGUI – Index Box

Improve
Improve
Like Article
Like
Save
Share
Report

Index Box : It is used to display a window having a multiple options i.e buttons in EasyGUI, it can be used where there is a need to get the option selected by the user. It is similar to button box but is used at places where buttons are having same name, it specify the selected button according to the index of it. Index of buttons start from 0, below is how the index box looks like

In order to do this we will use indexbox method

Syntax : indexbox(message, title, buttons)

Argument : It takes 3 arguments, first string i.e message/information to be displayed, second string i.e title of the window and third is list of strings i.e buttons

Return : It returns return of the index selected by the user

Example :
In this we will create a index box with added buttons, when any button is pressed it will show the specific message on the screen according to the index, below is the implementation




# importing easygui module
from easygui import *
  
# message / information to be displayed on the screen
message = "Select any one button"
  
# title of the window
title = "GfG - EasyGUI"
  
# list of buttons 
buttons = ["First", "Second", "Third", "Fourth"]
  
# creating a index box
output = indexbox(message, title, buttons)
  
  
# showing new message according to the buttons pressed
# if index is 0
if output == 0:
      
    # message / information
    message = "First"
# if index is 1
elif output == 1:
      
    # message / information
    message = "Second"
      
# if index is 2
elif output == 2:
      
    # message / information
    message = "Third"
      
# if index is 3
elif output == 3:
      
    # message / information
    message = "Fourth"
  
      
# message 
message = message + " Button Pressed"
# title of the window
title = "GfG - EasyGUI"
   
# creating a message box
msg = msgbox(message, title)
     


Output :


Another Example :
In this we will create a index box without setting any buttons, when any button is pressed it will show the specific message on the screen according to the index, below is the implementation




# importing easygui module
from easygui import *
  
# message / information to be displayed on the screen
message = "Select any one button"
  
# title of the window
title = "GfG - EasyGUI"
  
# creating a index box
output = indexbox(message, title)
  
  
# showing new message according to the buttons pressed
# if index is 0
if output == 0:
      
    # message / information
    message = "First"
# if index is 1
elif output == 1:
      
    # message / information
    message = "Second"
      
  
# message 
message = message + " Button Pressed"
  
# title of the window
title = "GfG - EasyGUI"
   
# creating a message box
msg = msgbox(message, title)
     


Output :




Last Updated : 05 Sep, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads