import tkinter

root = tkinter.Tk()
root.geometry("200x200")

buttons=[i for i in range(10)]

def getNext():
    #If specific button is pressed, output "YES"

for num in buttons:
    btn=tkinter.Button(root, text=num,command=getNext)
    btn.pack(side=tkinter.TOP)

Use partial to pass something to the function, and the function will do something based on the value. This example prints what was passed to the function. Note that the Python Style Guide suggests function names should be lower case letters and underscores https://www.python.org/dev/peps/pep-0008/

root = tkinter.Tk()
root.geometry("200x300")
##buttons=range(10)
button_list=[]

def get_next(button_num):
    print("button number =", button_num)
    ## change the color of the button pressed to show how the list works
    button_list[button_num].config(bg="lightblue")

for num in range(10):
    btn=tkinter.Button(root, text="Button %d" % (num),
                       command=partial(get_next, num))
    btn.pack(side=tkinter.TOP)
    ## save a reference to the button so it can be used in get_next
    ## the button number corresponds to the offset in the list
    button_list.append(btn)

root.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.