Advertisement
DecaK

Untitled

Jun 11th, 2018
1,884
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. from tkinter import *
  2.  
  3. root = Tk()
  4.  
  5. files = [] #creates list to replace your actual inputs for troubleshooting purposes
  6. btn = [] #creates list to store the buttons ins
  7.  
  8. for i in range(50): #this just popultes a list as a replacement for your actual inputs for troubleshooting purposes
  9. files.append("Button"+str(i))
  10.  
  11. for i in range(len(files)): #this says for *counter* in *however many elements there are in the list files*
  12. #the below line creates a button and stores it in an array we can call later, it will print the value of it's own text by referencing itself from the list that the buttons are stored in
  13. btn.append(Button(root, text=files[i], command=lambda c=i: onButtonClicked(c)))
  14. btn[i].pack() #this packs the buttons
  15.  
  16. def onButtonClicked(button_id):
  17. print("Button" + str(button_id) + " is clicked!");
  18.  
  19. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement