Python Tkinter help

I have a school project (We’re allowed help from any source, not cheating) to create a GUI using tkinter and read in a .db file to print the results in the GUI. The .db file is a list of game details. I have completed the code to read the .db file and the code for the GUI. We’re supposed to be able to sort and search the data but i can’t even get this part finished in ordre to start that. However, for the final part when I have to print the list in the GUI, only the final result in the list is being displayed. The program has to be finished for 1 week today (26 January 2021) and I just need help with this final part. This is my first time using tkinter so I am aware the GUI is very simple :woozy_face: !

I just need all the results from the list to be printed instead of just the last result.

I’ll attach my code below:

indent preformatted text by 4 spaces
import sqlite3

from tkinter import *
from tkinter import messagebox

def setupConnection():
global db
db = sqlite3.connect(‘gamesArchive.db’)

global c
c = db.cursor()

global tableName
tableName = 'games'

def getAllGames(db):
c.execute(’’‘SELECT * FROM games’’’)
data =
for row in c.fetchall():
data.append(row)
return data

window = Tk()
window.title(“Welcome to Zach’s Game Archive!”)

window.configure(background=‘blue’)

lbl = Label(window, text=“Click the box to view the game archives”, font=(“Arial Bold”, 25))

lbl.grid(column=0, row=0)
window.geometry(‘5000x3000’)

def clicked():
setupConnection()
gamesData = getAllGames(db)
for game in gamesData:
lbl.configure(text= game, font=(“Arial Bold”, 8))

btn = Button(window, text=“Click Me”, command=clicked, bg=“orange”, fg=“red”, height = 10, width = 20)

btn.grid(column=1000, row=1000)

window.mainloop()

I have a school project (We’re allowed help from any source, not
cheating)

That is welcome here.

to create a GUI using tkinter and read in a .db file to print the
results in the GUI. The .db file is a list of game details. I have
completed the code to read the .db file and the code for the GUI. […]
when I have to print the list in the GUI, only the final result in the
list is being displayed. […]

I presume the list is to be displayed in the label. This code:

for game in gamesData:
    lbl.configure(text= game, font=("Arial Bold", 8))

iterates through the gamesData and sets the label to each in turn.
Overwriting the previous label display.

In most GUIs a label can contain quite a lot of text. Above, your
settings the label many time. Instead, set it just once to a list of all
the games. Maybe something like:

label_text = "\n".join(gamesData)
lbl.configure(text=label_text, font=("Arial Bold", 8))

I’m not a Tk user: you may find that Tk labels accept some formattings,
maybe HTML. Try:

label_text = "<BR>\n".join(gamesData)

and see if you get line breaks. Of, conversely, lots of "
"s.

Cheers,
Cameron Simpson cs@cskk.id.au