Use ajax to call a server side php script, which will execute the function you want.
The vanilla js can be a bit intimidating if you're new to it. To get a quick result, while taking time to learn 'proper js', you could use jQuery and it's .ajax method (or its shortcut methods). Other libraries will have similar methods.
root = tkinter.Tk()
buttons=[i for i in range(10)]
#If specific button is pressed, output "YES"
for num in buttons: