May-24-2023, 04:37 AM
I have a program that records score when practicing darts, then shows them in a high score table.
And this code displays it.
I have tried both cur.close and connection.close with no success.
Any help would be greatly appreciated.
def addToDb(self): name = self.name total = self.runningTotal connection = sqlite3.connect('highscores.db') cur = connection.cursor() insert_statement = ''' INSERT INTO finisheshigh(playername, score) VALUES(?, ?); ''' insert_values = (name, total) cur.execute(insert_statement, insert_values) print("done") connection.commit() cur.close()I have this code which adds the result to the database.
And this code displays it.
connection = sqlite3.connect('highscores.db') cur = connection.cursor() connection.commit() # populate rtb table read_query = '''SELECT * FROM rtbhigh ORDER BY score DESC''' cur.execute(read_query) items = cur.fetchall() tk.Label(frame1, text="Round the board").grid(row=0,column=0, columnspan=3) row = 1 buttonnumber = 1 for item in items: fullframe = tk.Frame(frame1, highlightbackground="black", highlightthickness=1) fullframe.grid(row=row, column=0) tk.Label(fullframe, text=buttonnumber).grid(row=0, column=0) tk.Label(fullframe, text=item[0], width=20).grid(row=0, column=1) tk.Label(fullframe, text=item[1]).grid(row=0, column=2) row += 1 buttonnumber +=1 #populate finishes table read_query = '''SELECT * FROM finisheshigh''' cur.execute(read_query) items = cur.fetchall() tk.Label(frame2, text="Finishes").grid(row=0,column=0, columnspan=3) row = 1 buttonnumber = 1 for item in items: fullframe = tk.Frame(frame2, highlightbackground="black", highlightthickness=1) fullframe.grid(row=row, column=0) tk.Label(fullframe, text=buttonnumber).grid(row=0, column=0) tk.Label(fullframe, text=item[0], width=20).grid(row=0, column=1) tk.Label(fullframe, text=item[1]).grid(row=0, column=2) row += 1 buttonnumber +=1 connection.commit() cur.close()The issue I am having is the result which has just been input does not show in the displayed table, if the program is shut down then restarted it is there.
I have tried both cur.close and connection.close with no success.
Any help would be greatly appreciated.