1

i'm trying to create buttons in tkinter while iteratng a list, the buttons are created with the correct text but the command prints '6' for every button, how can i define different commands for each button?

from tkinter import *
root = Tk()

list = [1,2,3,4,5,6]

for number in list:
    Button(root, text=number, command=lambda:print(number)).pack()

root.mainloop()
lockstock
  • 11
  • 1

0 Answers0