Skip to content
Advertisement

Database Error: NameError: name ‘db’ is not defined. What am I doing wrong?

On the web I found this illustration to create a database with gui with Tkinter. Everything ok, except when I enter the data and click on the Add button. I’m getting: NameError: name 'db' is not defined

I think what I am wrong is nonsense in this part of the code. What am I doing wrong?

Here is my code uploaded su un editor online. I am writing it here because it is too long to enter. I am new and having difficulty with StackOverflow. If we can figure out the error, I’ll update the question with the code I’m wrong.

Advertisement

Answer

You have this:

Right away, you can see a problem there. You have conn and curr defined outside the class and inside. It seems clear that the rest of your code expects db to be an instance of the Database class. So you need:

and you need to do that before any of the code that refers to db.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement