Python EasyGUI – Showing Image in a Button Box
Last Updated :
14 Apr, 2023
In this article we will see how we can add or show image in the button box. Button box 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
When we invoke the buttonbox function (or other functions that display a button box, such as msgbox, indexbox, ynbox, etc.), we can specify the keyword argument image=img where img is the filename of an image. The file can be .gif. Usually, we can use other images such as .png.
In order to do this we will use buttonbox method
Syntax : buttonbox(text, title, image=img, choices=button_list)
Argument : It takes 4 arguments, first string i.e text to be displayed, second string i.e title of the window and third and fourth is keyword argument which is image source and the button choices
Return : It returns the text of the button that the user selected
Example : In this we will create a button box with a image, and user will be allowed to select any button and message will appear according to the message, below is the implementation
Python3
from easygui import *
text = "Message to be displayed on the window GfG"
title = "Window Title GfG"
button_list = []
button1 = "Average"
button2 = "Good"
button3 = "Very Good"
button_list.append(button1)
button_list.append(button2)
button_list.append(button3)
img = "gfg.png"
output = buttonbox(text, title, image = img, choices = button_list)
title = "Message Box"
message = "You selected : " + output
msg = msgbox(message, title)
|
Output :
Another Example :
Python3
from easygui import *
text = "How much do you like the image given below"
title = "Window Title GfG"
button_list = []
button1 = "Average"
button2 = "Good"
button3 = "Very Good"
button_list.append(button1)
button_list.append(button2)
button_list.append(button3)
img = "dog_image.png"
output = buttonbox(text, title, image = img, choices = button_list)
title = "Message Box"
message = "You selected : " + output
msg = msgbox(message, title)
|
Output :
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...