Hi I am quite new to using python
I have modified and added to a pre-existing script, so there are lots of looses ends to finish.
My question is that eventually, I want to search an SQLite database and update my Tkinter widget with a count rest of the number of rows found on that search. But to aid learning all I want to do is update an entry box with a number to make sure I understand the process.
I have in def monitor an entry box and using def entry1 I can't seem to pass a result into it when I push the display counts button.
I created an account user/ password A/A to login to the second screen
I have modified and added to a pre-existing script, so there are lots of looses ends to finish.
My question is that eventually, I want to search an SQLite database and update my Tkinter widget with a count rest of the number of rows found on that search. But to aid learning all I want to do is update an entry box with a number to make sure I understand the process.
I have in def monitor an entry box and using def entry1 I can't seem to pass a result into it when I push the display counts button.
I created an account user/ password A/A to login to the second screen
#imports from tkinter import * from tkinter import messagebox as ms import sqlite3 # make database and users (if not exists already) table at programme start up with sqlite3.connect('quit.db') as db: c = db.cursor() c.execute('CREATE TABLE IF NOT EXISTS user (username TEXT NOT NULL ,password TEXT NOT NULL);') db.commit() db.close() #main Class class main: def __init__(self,master): # Window self.master = master # Some Usefull variables self.username = StringVar() self.level1 = StringVar() #lets self.level2 = StringVar() self.level3 = StringVar() self.level4 = StringVar() self.password = StringVar() self.n_username = StringVar() self.n_password = StringVar() #Create Widgets self.widgets() #Login Function def login(self): #Establish Connection with sqlite3.connect('quit.db') as db: c = db.cursor() #Find user If there is any take proper action find_user = ('SELECT * FROM user WHERE username = ? and password = ?') c.execute(find_user,[(self.username.get()),(self.password.get())]) result = c.fetchall() if result: # self.logf.pack_forget() # Destroys frame #self.log.f['text'] = self.username.get() + '\n Accsess Granted' self.monitor() # INSERT COUNTS HERE else: ms.showerror('Oh dear!','Your names not on the list your not comming in.') def new_user(self): #Establish Connection with sqlite3.connect('quit.db') as db: c = db.cursor() #Find Existing username if any take proper action find_user = ('SELECT * FROM user WHERE username = ?') c.execute(find_user,[(self.username.get())]) if c.fetchall(): ms.showerror('Error!','Username Taken Try a Diffrent One.') else: ms.showinfo('Success!','Account Created!') self.log() #Create New Account insert = 'INSERT INTO user(username,password) VALUES(?,?)' c.execute(insert,[(self.n_username.get()),(self.n_password.get())]) db.commit() #Frame Packing Methords def log(self): self.username.set('') self.password.set('') self.crf.pack_forget() self.head['text'] = 'LOGJDJKDJKJCIN' self.logf.pack() def cr(self): self.n_username.set('') self.n_password.set('') self.logf.pack_forget() self.head['text'] = 'Create Account' self.crf.pack() #Draw Widgets def widgets(self): self.head = Label(self.master,text = 'Login Screen',font = ('',35),pady = 10) self.head.pack() self.logf = Frame(self.master,padx =10,pady = 10) Label(self.logf,text = 'Username: ',font = ('',20),pady=5,padx=5).grid(sticky = W) Entry(self.logf,textvariable = self.username,bd = 5,font = ('',15)).grid(row=0,column=1) Label(self.logf,text = 'Password: ',font = ('',20),pady=5,padx=5).grid(sticky = W) Entry(self.logf,textvariable = self.password,bd = 5,font = ('',15),show = '*').grid(row=1,column=1) Button(self.logf,text = ' Login ',bd = 3 ,bg = "green" ,font = ('',15),padx=5,pady=5,command=self.login).grid() Button(self.logf,text = ' Create Account ',bd = 3 ,bg = "white" ,font = ('',15),padx=5,pady=5,command=self.cr).grid(row=2,column=1) self.logf.pack() self.crf = Frame(self.master,padx =10,pady = 10) Label(self.crf,text = 'Username: ',font = ('',20),pady=5,padx=5).grid(sticky = W) Entry(self.crf,textvariable = self.n_username,bd = 5,font = ('',15)).grid(row=0,column=1) Label(self.crf,text = 'Password: ',font = ('',20),pady=5,padx=5).grid(sticky = W) Entry(self.crf,textvariable = self.n_password,bd = 5,font = ('',15),show = '*').grid(row=1,column=1) Button(self.crf,text = 'Create Account',bd = 3 ,font = ('',15),padx=5,pady=5,command=self.new_user).grid() Button(self.crf,text = 'Go to Login',bd = 3 ,font = ('',15),padx=5,pady=5,command=self.log).grid(row=2,column=1) def monitor(self): self.logf.pack_forget() # Destroys frame self.head.pack_forget() # Destroys frame self.header = Label(self.master,text = 'Bearing defects',font = ('',35),pady = 10) self.header.pack() self.disp1 = Frame(self.master,padx =10,pady = 10) Label(self.disp1,text = 'Level 1: ',font = ('',20),pady=5,padx=5).grid(sticky = W) Label(self.disp1,text = 'Level 2: ',font = ('',20),pady=5,padx=5).grid(sticky = W) Label(self.disp1,text = 'Level 3: ',font = ('',20),pady=5,padx=5).grid(sticky = W) Label(self.disp1,text = 'Level 4: ',font = ('',20),pady=5,padx=5).grid(sticky = W) Entry(self.disp1,textvariable = self.level1,bd = 5,font = ('',15)).grid(row=0,column=1) Entry(self.disp1,textvariable = self.level2,bd = 5,font = ('',15)).grid(row=1,column=1) Entry(self.disp1,textvariable = self.level3,bd = 5,font = ('',15)).grid(row=2,column=1) Entry(self.disp1,textvariable = self.level4,bd = 5,font = ('',15)).grid(row=3,column=1) Button(self.disp1,text = ' Display Counts ',bd = 3 ,bg = "green" ,font = ('',15),padx=5,pady=5,command=self.level).grid()#comand delet inm sqlite3 Button(self.disp1,text = ' Reset Database ',bd = 3 ,bg = "red" ,font = ('',15),padx=5,pady=5,command=self.wipe_data).grid(row=4,column=1)# export csv file or db file self.disp1.pack() def wipe_data(self): with sqlite3.connect('logging.db') as db: c = db.cursor() c.execute('DELETE FROM logt;',); db.commit() c.close() db.close() def export_data(self): #unused button define with sqlite3.connect('logging.db') as db: c = db.cursor() def level(self): #with sqlite3.connect('logging.db') as db: # c = db.cursor() # cur.execute("SELECT * FROM logt WHERE amps=>5") #Count returned rows before inserting to entry box #self.level1.delete(0, END) lv = int(4) self.level1.insert(0, 4) print("Hello World") def level_2(self): with sqlite3.connect('logging.db') as db: c = db.cursor() cur.execute("SELECT * FROM logt WHERE amps=>15") db.commit() c.close() db.close() def level_3(self): with sqlite3.connect('logging.db') as db: c = db.cursor() cur.execute("SELECT * FROM logt WHERE amps=>35") db.commit() c.close() db.close() def level_4(self): with sqlite3.connect('logging.db') as db: c = db.cursor() cur.execute("SELECT * FROM logt WHERE amps=>50") db.commit() c.close() db.close() #create window and application object root = Tk() root.title("Bearing Current Program") main(root) root.mainloop()