Wednesday, July 3, 2024
HomeLanguagesPythonPython EasyGUI – Choice Box

Python EasyGUI – Choice Box

Choice Box : It is used to display a window having a multiple options i.e items in EasyGUI, it can be used where there is a need to select any one item among a group of items, it consist of title, message to be displayed, group of items and a pair of “Ok”, “Cancel” button to confirm the selection of the item. Below is how the choice box looks like 

In order to do this we will use choicebox method 

Syntax : choicebox(message, title, choices) 

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 items 

Return : It returns the display text of the selected item else None

Example : In this we will create a choice box with multiple items, when any item is confirmed it will show the specific message on the screen according to the item, below is the implementation 

Python3




# importing easygui module
from easygui import *
 
# message to be displayed
text = "Selected any one item"
 
# window title
title = "Window Title GfG"
 
# item choices
choices = ["Geek", "Super Geeek", "Super Geek 2", "Super Geek God"]
 
# creating a button box
output = choicebox(text, title, choices)
 
# title for the message box
title = "Message Box"
 
# message
message = "You selected : " + str(output)
 
# creating a message box
msg = msgbox(message, title)


Output :

Another Example : In this we will create a choice box without adding any items, when any item is confirmed it will show the specific message on the screen according to the item, below is the implementation 

Python3




# importing easygui module
from easygui import *
 
# message to be displayed
text = "Selected any one item"
 
# window title
title = "Window Title GfG"
 
# creating a button box
output = choicebox(text, title)
 
# title for the message box
title = "Message Box"
 
# message
message = "You selected : " + str(output)
 
# creating a message box
msg = msgbox(message, title)


Output :

Shaida Kate Naidoo
am passionate about learning the latest technologies available to developers in either a Front End or Back End capacity. I enjoy creating applications that are well designed and responsive, in addition to being user friendly. I thrive in fast paced environments. With a diverse educational and work experience background, I excel at collaborating with teams both local and international. A versatile developer with interests in Software Development and Software Engineering. I consider myself to be adaptable and a self motivated learner. I am interested in new programming technologies, and continuous self improvement.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments