After making an array of buttons using tkinter, the buttons are not clickable, almost as if the unique commands I'm assigning each button are not sticking to each button
I've tried using the lambda method and the partial method, but neither seem to work
import tkinter as tk
from functools import partial
#Sets root as Tk
root = Tk()
#Makes our GUI space
canvas = Canvas(root, width = 1600, height = 1100, bg = "white")
class App:
def clicked(self, i):
print("Clicked")
print(self.button[i])
def __init__(self, root):
self.root = root
self.button = [];
#Allows button size to be set in pixels
pixel = tk.PhotoImage(width=1, height=1, master = root)
for i in range(5):
#Makes each button and adds it to self.button array
self.button.append(tk.Button(root, bg = "red", image=pixel,
width = 10, height = 10,
command=lambda: clicked(i)))
#I have also tried:
#command=partial(clicked, i)
#command=lambda i=i: clicked(i)
#Places button on canvas
self.button[i].place(x=10*i, y=10*i, in_=canvas)
canvas.pack()
App(root)
root.mainloop()
I am expecting to be able to click each of these button and see the word "Clicked" appear in the Jupyter terminal line. But I get nothing...
I've looked here and here and a few other places, but I'm still stuck on something...any ideas?