【发布时间】:2021-10-05 04:19:22
【问题描述】:
我正在开发一个有两个屏幕的密码管理器应用程序。一个屏幕用于用户登录/注册,另一个屏幕用于向用户显示不同 url 的用户名和密码。我为此创建了一个单独的 kv 文件。现在在第二个屏幕中,我想添加一个数据表,它将以排列良好的格式显示用户数据。
根据 kivy 文档,我们只能在主程序中添加数据表,而不是在 .kv 文件中,但在我的情况下,我已经有一个 .kv 文件。那么如何在第二个屏幕的程序中添加数据表?
from kivy.config import Config
from kivy import Config
Config.set('graphics', 'width', '500')
Config.set('graphics', 'height', '600')
Config.set('graphics', 'resizable', 'False')
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.screenmanager import ScreenManager, Screen
from kivymd.uix.datatables import MDDataTable
import sqlite3
class MainWindow(Screen):
pass
class SecondWindow(Screen):
pass
class WindowManager(ScreenManager):
pass
class MainApp(MDApp):
def build(self):
Config.set('graphics', 'resizable', False)
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Purple"
# self.background_color = (0,0,0,0)
return Builder.load_file("login.kv")
MainApp().run()
我的 .kv 文件------>
WindowManager:
MainWindow:
SecondWindow:
<MainWindow>:
name: "main"
MDCard:
size_hint:None,None
size:400,500
pos_hint:{"center_x":.5,"center_y":.5}
elevation:10
padding:25
spacing:25
background_color:25
orientation:"vertical"
<SecondWindow>:
name: "second"
BoxLayout:
orientation:"vertical"
size:root.width,root.height
padding:30
spacing:25
Label:
markup:True
font_size:35
text:"SAVED PASSWORDS"
halign: "left"
size_hint_y: None
height:self.texture_size[1]
#padding_y:-15
MDDataTable:
text: "Go Back"
【问题讨论】:
-
这个答案可能对你有帮助,它有一个登录屏幕,稍后需要将该信息移动到一个表中,刷新现有表中的新数据stackoverflow.com/questions/69083706/…
标签: python datatable kivy kivymd