Dynamic table display using kivy and sqlite 3(使用 kivy 和 sqlite 3 的动态表格显示)
问题描述
我正在开发一个 GUI 来管理库存(Python 3.4、Sqlite3 和 Kivy 1.9.1),我的想法是能够根据产品的不同特征识别产品,这些特征在一个数据库.
I am working on a GUI to manage inventory (Python 3.4, Sqlite3 and Kivy 1.9.1) and the idea is to be able to recognize products based on their different features, which are listed in a database.
有没有办法使用 kivy 显示 sqlite 表?我认为 ListView
可能是解决方案,但我真的很难理解如何使用正确的 args_converter
制作一个 CustomListItem
以获得几列不同的标签.
Is there a way to display a sqlite table using kivy ? I think a ListView
could be the solution but I am really struggling to understand how to make a CustomListItem
with the right args_converter
to get several columns with different labels in them.
推荐答案
是的,您可以为此使用 RecycleView
.
试试这个例子:
Yes, you can use RecycleView
for this.
Try this example:
import sqlite3 as lite
con = lite.connect('test.db')
cur = con.cursor()
try:
with con:
cur.execute("CREATE TABLE Cars(Id INT, Name TEXT, Price INT)")
cur.execute("INSERT INTO Cars VALUES(1,'Audi',52642)")
cur.execute("INSERT INTO Cars VALUES(2,'Mercedes',57127)")
cur.execute("INSERT INTO Cars VALUES(3,'Skoda',9000)")
cur.execute("INSERT INTO Cars VALUES(4,'Volvo',29000)")
cur.execute("INSERT INTO Cars VALUES(5,'Bentley',350000)")
cur.execute("INSERT INTO Cars VALUES(6,'Citroen',21000)")
cur.execute("INSERT INTO Cars VALUES(7,'Hummer',41400)")
cur.execute("INSERT INTO Cars VALUES(8,'Volkswagen',21600)")
except:
pass
from kivy.uix.boxlayout import BoxLayout
from kivy.base import runTouchApp
from kivy.lang import Builder
from kivy.properties import ListProperty
Builder.load_string("""
<MyLayout>:
Button:
text: "Get data"
on_press: root.get_data()
RecycleView:
data: [{'text':"Id:{} Brand:{} Km:{}".format(id,name,km)} for id,name,km in root.rows]
viewclass: "Label"
RecycleBoxLayout:
default_size: None, dp(56)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
""")
class MyLayout(BoxLayout):
rows = ListProperty([("Id","Brand","Price")])
def get_data(self):
cur.execute("SELECT * FROM Cars")
self.rows = cur.fetchall()
print(self.rows)
runTouchApp(MyLayout())
这篇关于使用 kivy 和 sqlite 3 的动态表格显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 kivy 和 sqlite 3 的动态表格显示


- 在SQL中,如何为每个组选择前2行 2021-01-01
- SQL 临时表问题 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01