Python EasyGUI – Button Box
Last Updated :
05 Sep, 2020
EasyGUI is a module for very simple, very easy GUI programming in Python. EasyGUI is different from other GUI generators in that EasyGUI is NOT event-driven. Instead, all GUI interactions are invoked by simple function calls. Unlike other complicated GUI’s EasyGUI is the simplest GUI till now.
Button Box : It is used to display a window having multiple buttons in EasyGUI, it can be used where there is condition to select one among lot of buttons for example buttons in lift at a time user can opt only one option, below is how the normal button box looks like
In order to do this we will use buttonbox
method
Syntax : buttonbox(text, title, button_list)
Argument : It takes 3 arguments, first string i.e text to be displayed, second string i.e title of the window and third list of button(strings)
Return : It returns the text of the button that the user selected
Example :
In this we will create a button box windows having a three buttons which user can select and selected button text will get printed, below is the implementation
from easygui import *
text = "Message to be displayed on the window GfG"
title = "Window Title GfG"
button_list = []
button1 = "First"
button2 = "Second"
button3 = "Third"
button_list.append(button1)
button_list.append(button2)
button_list.append(button3)
output = buttonbox(text, title, button_list)
print ( "User selected option : " , end = " " )
print (output)
|
Output :
User selected option : Second
Another example :
from easygui import *
text = "Message to be displayed on the window GfG"
title = "Window Title GfG"
output = buttonbox(text, title)
print ( "User selected option : " , end = " " )
print (output)
|
Output :
User selected option : Button[3]
Share your thoughts in the comments
Please Login to comment...