Tkinter is a Python module which is used to create GUI (Graphical User Interface) applications with the help of varieties of widgets and functions. Like any other GUI module it also supports images i.e you can use images in the application to make it more attractive.
Image can be added with the help of
PhotoImage() method. This is a Tkinter method which means you don’t have to import any other module in order to use it.
Important: If both image and text are given on Button, the text will be dominated and only image will appear on the Button. But if you want to show both image and text then you have to pass compound in button options.
Button(master, text = "Button", image = "image.png", compound=LEFT)
compound = LEFT-> image will be at left side of the button
compound = RIGHT-> image will be at right side of button
compound = TOP-> image will be at top of button
compound = BOTTOM-> image will be at bottom of button
photo = PhotoImage(file = "path_of_file")
path_of_file is any valid path available on your local machine.
In output observe that only image is shown on the button and the size of the button is also bigger than the usual size it is because we haven’t set the size of the image.
Code #2: To show both image and text on Button.
Observe that both text and image are appearing as well as size of the image is also small.
- Python | Add style to tkinter button
- Python | Creating a button in tkinter
- Open a new Window with a button in Python-Tkinter
- Add image button using .kv file in kivy
- PyQt5 – Add image icon on a Push button
- wxPython - Add Image in Button
- Python Tkinter | Create LabelFrame and add widgets to it
- Image Viewer App in Python using Tkinter
- wxPython - Image on button in Python
- Python EasyGUI – Showing Image in a Button Box
- PyQt5 – How to add action to a button ?
- PyQt5 - How to add icon to Radio Button ?
- PyQt5 QSpinBox - Add border to the down button
- Use image as a button in kivy
- PyQt5 – How to make a button with image ?
- PyQt5 | How to adjust the image inside Push Button ?
- PyQt5 - Background image to Radio Button
- PyQt5 - Background image to indicator of Radio Button
- PyQt5 – Background image of Radio button for checked state
- PyQt5 – Background image of Radio button for unchecked state
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.