Can tkinter create custom buttons from an image or icon like this?

- 540
- 2
- 6
- 22
-
1yes, you can create buttons with images and text, or just images, with or without a raised border, and with whatever colors you want. It's all documented in the options for the button widget. – Bryan Oakley Aug 20 '16 at 13:21
2 Answers
It's possible!
If you check out the button documentation, you can use an image to display on the button.
For example:
from tkinter import *
root = Tk()
button = Button(root, text="Click me!")
img = PhotoImage(file="C:/path to image/example.gif") # make sure to add "/" not "\"
button.config(image=img)
button.pack() # Displaying the button
root.mainloop()
This is a simplified example for adding an image to a button widget, you can make many more cool things with the button widget.
-
is there a way to do this without images? like custom shapes with masks? – Ishan Jindal Mar 13 '22 at 01:39
I created a library called CustomTkinter, and with it you can create more or less exactly what is shown in the images above. CustomTkinter provides widgets to be used similar to Tkinter. They can be customised in color and shape, here I tried to create something similar to the image above:
There is not also a button, but many other elements, and it also supports a dark and light theme:
You can check out the library here:
https://customtkinter.tomschimansky.com https://github.com/TomSchimansky/CustomTkinter
A simple example would be:
import customtkinter
customtkinter.set_appearance_mode("System")
customtkinter.set_default_color_theme("blue")
app = customtkinter.CTk() # create window
app.geometry("400x240")
def button_callback():
print("button pressed")
# create button
button = customtkinter.CTkButton(app, command=button_callback)
button.grid(row=0, column=0, padx=20, pady=20)
app.mainloop()
which gives the following on macOS:

- 723
- 1
- 7
- 16
-
I can't get this tkinter_custom_button, how to install it? I do use Linux. – Ziggy Witkowski Feb 19 '21 at 12:26
-
1You can find the file when you click on the link, to download it you have to download the whole GitHub repository, then you can find it under /documentation. To use it just place it next to your .py file, then you can import it. – Tom Feb 19 '21 at 12:51
-
right, thanks. Thought there're are only examples how to use it. Thanks – Ziggy Witkowski Feb 19 '21 at 12:58
-
This is perfect for what I need. Could you possibly show me how I could replace the text with an image? I tried but it didn't display the image. – LordCommanderMay Mar 08 '21 at 05:58
-
2I have added the option to put an image on the `TkinterCustomButton`. In the /test_custom_button.py file, I added a play button-image to button 7 as an example. You have to import Pil, load the image, convert it to a PhotoImage, and then pass it to the `TkinterCustomButton` with the argument `image`. – Tom Mar 08 '21 at 12:07
-