
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Add image on a Python Tkinter button
Tkinter, which is the GUI library for python programming has a feature to add images to the GUI buttons. This is useful for users to remember the symbols in the GUI rather than the text in the GUI. In the below Tkinter program we show how we can add an image to a GUI button. The photoimage method from the imageKT module is used. We mention the local path to the image file.
Example
from tkinter import * from PIL import ImageTk ,Image base = Tk() base.title('Start Button') img=ImageTk.PhotoImage(Image.open ("D:\button.jpg")) lab=Label(image=img) lab.pack() button=Button(base,text='exit',command=base.quit) button.pack() base.mainloop()
Output
Running the above code gives us the following result −
- Related Articles
- Add style to Python tkinter button
- Setting the position on a button in Tkinter Python?
- How to use an Image as a button in Tkinter?
- Creating a button in tkinter in Python
- How to draw a png image on a Python tkinter canvas?
- How to create a Button on a Tkinter Canvas?
- How to add an image in Tkinter?
- How to add a button to an image with CSS?
- On/Off Toggle Button Switch in Tkinter
- How do you create a Button on a Tkinter Canvas?
- How to exit from Python using a Tkinter Button?
- Tkinter button commands with lambda in Python
- Set Button on Image with CSS
- How to press a button without touching it on Tkinter?
- How to add an image to a button (action) in JavaFX?

Advertisements