Tkinter custom create buttons


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

enter image description here

Asked By: bunyaminkirmizi



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.pack() # Displaying the button


This is a simplified example for adding an image to a button widget, you can make many more cool things with the button widget.

Answered By: PyDer

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 new widgets for Tkinter, which can be customised in color and shape. Here I tried to create something similar to the image above:

enter image description here

You can find the example code to the above image here.

There is not also a Button, but many other elements, and it also supports a dark and light theme:

enter image description here

You can check out the library here:

A simple example would be:

import tkinter
import customtkinter


root_tk = customtkinter.CTk()  # create CTk window like the Tk window

def button_function():
    print("button pressed")

# Use CTkButton instead of tkinter Button
button = customtkinter.CTkButton(master=root_tk, command=button_function), rely=0.5, anchor=tkinter.CENTER)


which gives the following on macOS:

enter image description here

Answered By: Tom
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.