Search code examples
pythonbuttontkinterpython-3.5

Tkinter custom create buttons


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

enter image description here


Solution

  • 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.