0

here is my code:

button1 = Image.open("start_button.png")
button1 =  button1.resize((75,75), Image.ANTIALIAS)
button1 = ImageTk.PhotoImage( button1)
button1_c2 = c2.create_image(50,50, image =  button1, anchor = NW)

button2 = Image.open("start_button.png")
button2 = button2.resize((75,75), Image.ANTIALIAS)
button2= ImageTk.PhotoImage(button2)
button2= Button(root, text = "", image = button2)
button2_c2 = c2.create_window(500,400, window = button2)

What im trying to do is to have a image on canvas that acts as a button. First option imports the image, but it doesnt act as a button. So i tried the second option. It imports it on the canvas, acts as a button, but a white background got placed underneat that: here is the link, i cant post images yet

Is there a way to fix it ? By that i mean displaying an image on canvas that serves as a button and doesnt have the white background ? Thanks


Copy comment: I did the following:

buttonStart = Button(root, text = "", image = gombik, bg = "#545454", borderwidth = 0, relief = FLAT, activebackground = "#545454")

and it worked.


However ive ran into another issue..
When u press a regular button it gets "sunken" as u click it. With what ive done this doesnt happen and the button seems kinda dead.. I think ill fix it by having a function that adds another image on top of the previous one. This new image will look "sunken" and will stay this way as long as you hold the mouse click button. Then it gets removed. Any ideas ? Ive edited borderwidth and reliefe because of this: enter image description here

  • You can put a tkinter `Button` in a `Canvas` window created with `create_window()`. – martineau Feb 29 '20 at 12:50
  • OP already did it on button2. Just want to know how to remove the background color of the button. – acw1668 Feb 29 '20 at 13:07
  • You may set the background color of the button to the same as the canvas. – acw1668 Feb 29 '20 at 13:09
  • 2
    Does this answer your question? [How to bind events to Canvas items?](https://stackoverflow.com/questions/2786877/how-to-bind-events-to-canvas-items) – stovfl Feb 29 '20 at 13:36
  • @acw1668 that helped! Thanks! I did the following buttonStart = Button(root, text = "", image = gombik, bg = "#545454", borderwidth = 0, relief = FLAT, activebackground = "#545454") and it worked however ive ran into another issue.. When u press a regular button it gets "sunken" as u click it. With what ive done this doesnt happen and the button seems kinda dead.. I think ill fix it by having a function that adds another image on top of the previous one. This new image will look "sunken" and will stay this way as long as you hold the mouse click button. Then it gets removed. Any ideas ? – Jakub Jakubec Feb 29 '20 at 15:10
  • Why you set borderwith to zero and relief to FLAT? It is what you need to show it as a button. – acw1668 Feb 29 '20 at 16:07
  • @acw1668 Ive updated the post to make it more clear. – Jakub Jakubec Feb 29 '20 at 17:34

0 Answers0