Python EasyGUI – Yes No Box
Yes No Box : It is used to display a window having a two option yes or no in EasyGUI, it can be used where there is a need to get the answer of the question in form of yes or no, it displays two option yes or no for example when we want to ask user whether he is above 18 or not we will use yes no box, it is kind of similar to continue cancel box, below is how the continue cancel box looks like
In order to do this we will use ynbox method Syntax : ynbox(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 having exactly two values which is two option for yes and no Return : It returns True is yes is pressed else False
Example : In this we will create a yes no box, when any button is pressed it will show the specific message on the screen, below is the implementation
Python3
# importing easygui module from easygui import * # message / information to be displayed on the screen message = "Are you a Geek ?" # title of the window title = "GfG - EasyGUI" # creating a yes no box output = ynbox(message, title) # if user pressed yes if output: # message / information to be displayed on the screen message = "Thats Great !!" # title of the window title = "GfG - EasyGUI" # creating a message box msg = msgbox(message, title) # if user pressed No else : # message / information to be displayed on the screen message = "You should become a Geek, go to w3wiki to become one" # title of the window title = "GfG - EasyGUI" # creating a message box msg = msgbox(message, title) |
Output :
Another Example : In this we will create a yes no box and setting specific choice for yes and no button, when any button is pressed it will show the specific message on the screen, below is the implementation
Python3
# importing easygui module from easygui import * # message / information to be displayed on the screen message = "Are you a Geek ?" # title of the window title = "GfG - EasyGUI" # choices for yes and no button choices = ["Agree", "Disagree"] # creating a yes no box output = ynbox(message, title, choices) # if user pressed yes if output: # message / information to be displayed on the screen message = "Thats Great !!" # title of the window title = "GfG - EasyGUI" # creating a message box msg = msgbox(message, title) # if user pressed No else : # message / information to be displayed on the screen message = "You should become a Geek, go to w3wiki to become one" # title of the window title = "GfG - EasyGUI" # creating a message box msg = msgbox(message, title) |
Output :