Krob Ow
Krob Ow

Reputation: 21

How do you customize Tkinter buttons

there is a simple code to use an image as button, but this doesn't really do what I want...

CODE:

from Tkinter import *
window = Tk()

btn = Button(window)
pic = PhotoImage(file="submit.png")

btn.config(image = pic)
btn.pack()

window.configure(background = "#29746f")
window.geometry("{}x{}".format(150,100))

mainloop()

have a look on these screenshots please:

EXEPTATION: what I want

REALITY: what happens

So, how to make my image transparent and how to remove the rectangle border from my button ? Thanks.

Upvotes: 1

Views: 2662

Answers (1)

Shivam Pandya
Shivam Pandya

Reputation: 261

You have to set border width to 0 to remove that rectangle "border".

btn = Button(window, borderwidth= 0)

It will do the job.

To remove the background, you can use software like GIMP (Free and open source) or Photoshop.

However you will. not be able to remove the button background because tkinter does not support transparency best practice for customized button is to make them rectangular

Upvotes: 2

Related Questions