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

3 COMMENTS

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS