I am trying to FETCH DATA FROM SQLite3 database and then render it to a user interface using Python with Flet. Ian only able to get it to print in cmd prompt, but have failed to render the data to Flet UI.
TIA.
import sqlite3
import flet as ft
from db import db_path
class Profiles(ft.Container):
def init(self, page:ft.Page):
super().init()
tb=ft.DataTable(columns=[
ft.DataColumn(ft.Text(“FirstName”)),
ft.DataColumn(ft.Text(“LastName”)),
ft.DataColumn(ft.Text(“Email”)),
ft.DataColumn(ft.Text(“Password”),
],
rows=[]
)
#FETCH DATA FROM DATABASE TABLE
def calldb():
conn=sqlite3.connect(db_path)
cursor=conn.cursor()
cursor.execute("SELECT * FROM
user")
user=cursor.fetchall()
print(user)
#PUSH DATA FROM TABLE TO WIDGET ROW
if not user==””:
keys=['id', 'first_name', 'last_name', 'email', 'password']
result=[dict(zip(keys,values))for values in user]
for x in result:
tb.rows.append(
ft.DataRow(
cells=[
ft.DataCell(ft.Row([])),
ft.DataCell(ft.Text(x['first_name'])),
ft.DataCell(ft.Text(x['last_name'])),
ft.DataCell(ft.Text(x['email'])),
ft.DataCell(ft.Text(x['password'])),
]))
calldb()
myTable=ft.Column([ft.Row([tb], scroll=”always”)])
5oulCod3r is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.