I am new to coding in general (Python is my first language) and I ran into this problem while learning tkinter. My code is as follows:
from tkinter import *
window = Tk()
buttons = []
def position(pos):
print(pos)
for i in range(7):
buttons.append(Button(window, width = 10, height = 5, bg = "red", command = position(i)).grid(row = 0, column = i))
window.mainloop()
This does not work. I want to print the index of the button when that button is clicked. I have tried a few methods to accomplish this, but with no success. The buttons do not necessarily have to be in a list, however the first button must return 0, the second return 1, the third 2 etc. What is the simplest way to do this?