我创建了一个按钮,当按下它时,它会在表格中显示单个数据库记录,它在桌面版本上完美运行,但是当我为 android 编译时它不起作用,你能帮我吗?
这是代码:
"""
O aplicativo de teste
"""
import toga
from toga.style import Pack
from toga.style.pack import COLUMN, ROW
import sqlite3
import asyncio
class KaiqueTeste(toga.App):
def startup(self):
main_box = toga.Box()
self.label = toga.Label(text="Kaique Teste")
self.lista = toga.Table(['Cod', 'Nome', 'CPF/CNPJ', 'RG/IE', 'Endereço', 'Cplt/Ende', 'Pont Ref', 'Bairro', 'Cidade', 'UF'], missing_value="")
self.lista.MIN_HEIGHT = 180
self.btn = toga.Button('CONFIRMA', style=Pack(padding=5), on_press=self.confirmar_cli)
pasta = toga.Box(style=Pack(direction=COLUMN, padding=5))
pasta.add(self.label)
pasta.add(self.lista)
pasta.add(self.btn)
main_box.add(pasta)
self.main_window = toga.MainWindow(title=self.formal_name)
self.main_window.content = main_box
self.main_window.show()
async def confirmar_cli(self, widget):
try:
conn = sqlite3.connect(self.paths.app/'banco.db')
c = conn.cursor()
c.execute("SELECT cod, nome, cpf_cnpj, rg_ie, endereco, cplt_ende, pont_ref, bairro, cidade, uf FROM clientes WHERE cod = 1")
dados_lidos = c.fetchall()
await asyncio.sleep(0.1)
self.lista.data = dados_lidos
except Exception as ERROR:
print(ERROR)
def main():
return KaiqueTeste()