python - 如何在 Kivy python 代码中显示表格
问题描述
我想构建一个有管理员、代理和客户的应用程序。我想在 Kivy 屏幕应用程序上显示表格,并且应该显示的表格数据应该来自数据库。这是我的主要 python 文件代码
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
import json
from kivy.uix.boxlayout import BoxLayout
Builder.load_file('design.kv')
class MainScreen(Screen):
def goto_admin_page(self):
self.manager.current = "adminfirst_screen"
def goto_agent_page(self):
pass
def goto_customer_page(self):
pass
class AdminScreenFirst(Screen):
def go_to_adminsecond(self,uname,pword):
with open("users.json") as file:
users =json.load(file)
if uname in users and users[uname]['password'] == pword:
self.manager.current = "adminsecond_screen"
else:
self.ids.login_wrong.text = "Invalid Credentials.Please Contact the administrator"
class AdminScreenSecond(Screen):
def go_to_adminpending(self):
self.manager.current = "adminPending_screen"
def go_to_adminapproved(self):
self.manager.current = "adminsecond_screen"
def go_to_adminrejected(self):
self.manager.current = "adminsecond_screen"
class AdminPendingScreen(Screen):
def display(self):
pass
class Datatable(BoxLayout):
pass
class RootWidget(ScreenManager):
pass
class MainApp(App):
def build(self):
return RootWidget()
if __name__ == "__main__":
MainApp().run()
这是我的 kivy 文件
<MainScreen>:
GridLayout:
cols:1
GridLayout:
cols:1
padding:15,15
spacing:20,20
Label:
text:"Login"
font_size:"20sp"
Button:
text:"Admin"
on_press : root.goto_admin_page()
Button:
text:"Agent"
on_press : root.goto_agent_page()
Button:
text: "Customer"
on_press:root.goto_customer_page()
<AdminScreenFirst>:
GridLayout:
cols:1
padding:15,15
spacing:20,20
Label:
text:"Admin Login"
font_size:"20sp"
TextInput:
id:username
hint_text:"Username"
TextInput:
id:password
password:True
hint_text:"Password"
RelativeLayout:
Button:
text:"Login"
on_press : root.go_to_adminsecond(root.ids.username.text,root.ids.password.text)
size_hint :0.3,0.5
pos_hint: {'center_x' : 0.5 , 'center_y' : 0.6}
Label:
id:login_wrong
text:""
<AdminScreenSecond>:
GridLayout:
cols:1
padding:15,15
spacing:20,20
Label:
text:"Loan"
font_size:"20sp"
Button:
text:"Pending Request"
on_press:root.go_to_adminpending()
Button:
text:"Approved"
on_press: root.go_to_adminapproved()
Button:
text:"Rejected"
on_press: root.go_to_adminrejected()
<AdminPendingScreen>:
GridLayout:
cols:1
padding:15,15
spacing:20,20
Label:
text:"Loans"
Button:
text:"Display"
on_press: root.display()
Label:
id:display
text:""
<RootWidget>:
MainScreen:
name:"mainfirst_screen"
AdminScreenFirst:
name:"adminfirst_screen"
AdminScreenSecond:
name:"adminsecond_screen"
AdminPendingScreen:
name:"adminPending_screen"
我已经创建了数据库,并且我已经给出了创建数据库和表的命令,其中包含所有必需的信息
我已经构建了几个屏幕,但是我不知道如何在 kivy 代码中添加表以及我应该如何获取数据和检索数据来自应用程序并对其进行更改。我怎样才能做到这一点??我应该添加任何小部件或任何外部文件。
我会请求你帮我解决这个问题。先感谢您
解决方案
推荐阅读
- angular - 如何使用 msadal 库在登录 url 中添加 Response_type id_token+code
- docker - Docker Build Failing with Given as STDIN 作为输入
- networking - 使用端到端寻址
- flutter - flutter lint 参数类型规则用法
- matlab - 用 numpy.random 重现 Matlab 的 randi 的伪随机数
- javascript - React Docker 映像在本地机器上工作,但是当我将它移动到服务器时会出现 Hooks 错误
- javascript - 在 JavaScript 中按日期或布尔值对 JSON 对象数组进行排序
- laravel - spatie/laravel-short-schedule 如何在 cron 中使用它?
- python - 用python自动化java相关的东西:
- talend - 将 sql 查询转换为 talend 作业