I'm guessing that you want to connect to a SQL database from a class file that's not part of an aspx page? All you have to do is create a .cs file in your App_Code folder, and you can pretty much do what you want from there. I traditionally make a file called DBHandler.cs, in it's constructor I make a connection to the database, and then open it as I need to perform SQL tasks.
root = tkinter.Tk()
buttons=[i for i in range(10)]
#If specific button is pressed, output "YES"
for num in buttons: