Saturday, July 25, 2026
HomeLanguagesPython EasyGUI – Index Box

Python EasyGUI – Index Box

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 :

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6972 POSTS0 COMMENTS