Why isn't this working. I've made it as simple as posible - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Why isn't this working. I've made it as simple as posible (/thread-16686.html) |
Why isn't this working. I've made it as simple as posible - gcryall_Forum - Mar-10-2019 from tkinter import * from sqlite3 import * def center(toplevel): #Run outside the Class definition toplevel.update_idletasks() w = toplevel.winfo_screenwidth() h = toplevel.winfo_screenheight() size = tuple(int(_) for _ in toplevel.geometry().split('+')[0].split('x')) x = w/2 - size[0]/2 y = h/2 - size[1]/2 toplevel.geometry("%dx%d+%d+%d" % (size + (x, y))) class Earnings(): def __init__(self): print("About to go to self.connect_database") self.conn = self.connect_database(self) def connect_database(self): #create a database connection print("About to go to self.create_connection") def main(): root = Tk() root.geometry("1250x650") root.title("The Ryall Family Earnings") center(root) App = Earnings() root.mainloop() if __name__ == '__main__': main()Why do I keep getting the following message when I only enter the "self" parm when I go to self.connect_database(self)
RE: Why isn't this working. I've made it as simple as posible - Larz60+ - Mar-10-2019 There's absolutely no need for a class here, but if you insist: class Earnings: def __init__(self, dbname): print("Connecting to database") self.conn = sqlite3.connect(dbname) #replace line 28 with: App = Earnings('MyDatabaseName')and has to be called passing dbname as an argument this can be replaced with (placed on line 28) and eliminating the class: conn = sqlite3.connect('MyDatabaseName') RE: Why isn't this working. I've made it as simple as posible - Yoriz - Mar-10-2019 The error is because the line self.conn = self.connect_database(self)you don't pass self to self change it to self.conn = self.connect_database() RE: Why isn't this working. I've made it as simple as posible - gcryall_Forum - Mar-10-2019 Thank you Lar60+ and Yoriz |