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
from easygui import *
message = "Select any one button"
title = "GfG - EasyGUI"
buttons = [ "First" , "Second" , "Third" , "Fourth" ]
output = indexbox(message, title, buttons)
if output = = 0 :
message = "First"
elif output = = 1 :
message = "Second"
elif output = = 2 :
message = "Third"
elif output = = 3 :
message = "Fourth"
message = message + " Button Pressed"
title = "GfG - EasyGUI"
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
from easygui import *
message = "Select any one button"
title = "GfG - EasyGUI"
output = indexbox(message, title)
if output = = 0 :
message = "First"
elif output = = 1 :
message = "Second"
message = message + " Button Pressed"
title = "GfG - EasyGUI"
msg = msgbox(message, title)
|
Output :
Last Updated :
05 Sep, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...