Open In App

Python EasyGUI – Button Box

Improve
Improve
Like Article
Like
Save
Share
Report

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




# importing easygui module
from easygui import *
  
# message to be displayed 
text = "Message to be displayed on the window GfG"
  
# window title
title = "Window Title GfG"
  
# button list
button_list = []
  
# button 1
button1 = "First"
  
# second button
button2 = "Second"
  
# third button
button3 = "Third"
  
# appending button to the button list
button_list.append(button1)
button_list.append(button2)
button_list.append(button3)
  
  
# creating a button box
output = buttonbox(text, title, button_list)
  
# printing the button pressed by the user
print("User selected option : ", end = " ")
print(output)


Output :

User selected option :  Second

Another example :




# importing easygui module
from easygui import *
  
# message to be displayed 
text = "Message to be displayed on the window GfG"
  
# window title
title = "Window Title GfG"
  
# creating a button box
output = buttonbox(text, title)
  
# printing the button pressed by the user
print("User selected option : ", end = " ")
print(output)


Output :

User selected option :  Button[3]


Last Updated : 05 Sep, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads