Reputation: 5
While writing a simple interactive tic tac toe program in Python, using Tkinter to make a GUI, I faced a problem when coding a button.
Whenever you press a button in a Tkinter-based GUI, the button has this "animation" where as long as it's pressed in, it "jumps" slightly downwards and to the right - and when it's released, it jumps back to its original form. I was wondering whether it's possible to prevent this animation from taking place, but still have the button execute a command while being pressed (in other words: function as a button, but look like a plain image).
If it's worth anything, my relevant code is as follows:
import tkinter
from PIL import Image, ImageTk
window = tkinter.Tk()
button_image = ImageTk.PhotoImage(Image.open(<path>))
button = tkinter.Button(window, image=button_image, borderwidth=0)
button.grid(row=1)
window.mainloop()
Thank you in advance.
Upvotes: 0
Views: 778
Reputation: 96
I have a new answer, what if you do this?
button_image = ImageTk.PhotoImage(Image.open(<path>))
for _ in range(5):
button = tkinter.button(root, image=button_image, borderwidth=0, relief=SUNKEN)
button.grid(row=1)
root.mainloop()
Upvotes: 1
Reputation: 96
Maybe instead of a button a label?
panel = Label(root, image=button_image)
panel.image = button_image
panel.grid(row=1)
Upvotes: 0