I am new to SQLAlchemy and Python and am attempting to instantiate an sqlalchemy object within a Tkinter Button callback. Here is the code:
class Test(Base):
__tablename__ = "Tests"
id = Column(Integer, primary_key = True)
TestName = Column(String)
def __init__(self, TestName):
self.TestName = TestName
SaveTestButton = Button(master, text="Save to database", command=saveTest, fg="green", bg="white", font="Helvetica 10 bold")
NewTestEntry = Entry(master, text="", width = 100)
def saveTest():
NewTestName = NewTestEntry.get()
T = Test(NewTestName)
session.add(T)
session.commit()
Im getting the following error:
T = Test("NewTestName")
TypeError: 'NoneType' object is not callable
It seems to fail to recognize the sqlalchemy "Test" class within the callback. I have tried calling the saveTest function externally from tk to instantiate a Test class and it works. I have also instantiated other classes (not sqlalchemy based) within the callback so it seems really odd that it wouldnt work. There must be a way to do this... Any comments would be much appreciated. -Daniel W.