How To Add Image To Button In Python Tkinter
In this tutorial, we are going to see how to add image to button in Python Tkinter. Tkinter is the GUI library for Python programming. Tkinter has a feature to add images to Tkinter buttons. This is useful for users to remember the images in the GUI rather than the text. In the program below, we have used PhotoImage method of imageKT module to add images to Tkinter buttons, and we don’t forget to mention the local path to the image file.
How To Add Image To Button In Python Tkinter
from tkinter import * from tkinter.ttk import * # create tkinter window gui = Tk() # Adding widgets to the window Label(gui, text='Setting', font=('Verdana', 15)).pack(side=TOP, pady=10) # Create a photoimage object to use the image photo = PhotoImage(file = r"C:\Users\Desktop\icon.png") # Add image to button Button(gui, image=photo).pack(side=TOP) mainloop()
Output:
