I am trying to learn how to use tkinter and encountered a problem with buttons. What I think is happening is when I start the program it automatically calls the functions of the buttons whenever they are initialized.
code in question:
import tkinter as tk
test = tk.Tk()
x = lambda a: int((a - (a) % 3) / 3)
for i in range(9):
frame = tk.Frame(
master=test,
padx=1,
pady=1,
borderwidth=1
)
frame.grid(row=x(i), column=(i % 3))
button = tk.Button(
text=i,
master=frame,
width=10,
height=5,
bg="#333333",
fg="#ffffff",
command=print(i)
)
button.pack()
test.mainloop()