Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 9 - GUI Programming using Tkinter - Section 9.8 - Displaying Images - Check Point - MyProgrammingLab - Page 290: 9.27

Answer

To create a button that displays an image, you can use the PhotoImage class from Tkinter and set the image option of a button widget to the instance of PhotoImage. Here's an example: import tkinter as tk root = tk.Tk() image = tk.PhotoImage(file="c:\\pybook\\image\\canada.gif") button = tk.Button(root, image=image) button.pack() root.mainloop()

Work Step by Step

This code creates a Tk object that represents the main window, creates an instance of PhotoImage with the specified file path, and creates a button widget that displays the image. Finally, the button widget is packed into the main window using the pack geometry manager.
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.