访问 StringProperty 数据并使用它 (KIVY)



首先,我想指出的是,我已经检查了许多类似的问题,这些问题最终使用了StringProperty(),只有在on_release按钮或与其他UI小部件交互后访问其中的数据时,它似乎才能按预期工作。

我能够在屏幕登录中获取字符串属性并成功为其设置数据,如下所示

login.py

self.parent.parent.parent.admin_widget.mylocation =  str(self.ulocation) #DAta from textinput

在这里,我的 admin.py 文件如下所示: 我只是启动字符串属性,现在我有一个方法get_users,这个方法有一个 DataTable 并将小部件添加到屏幕,问题是最初加载时字符串属性为空,稍后在提交文本输入后更新,我希望更改屏幕应该调用get_users来捕获 StringProperty 中的当前位置值。如何获取此值 mylocation 并正确使用它来首次加载表中的数据?请帮帮我

class AdminWindow(BoxLayout):
data_items = ListProperty([])
mylocation = StringProperty()
def __init__(self, **kwargs):
super().__init__(**kwargs)
print(self.mylocation)
content = self.ids.scrn_contents
users = self.get_users()
userstable = DataTable(table=users)
content.add_widget(userstable)
def get_users_new(self):
#Here is where I access the stringProperty value
mycursor.execute("SELECT * FROM products WHERE location =%s", (self.mylocation,))
rows = mycursor.fetchall()
arrows = str(mycursor.rowcount)
self.ids.total_inventory.text = arrows + " Products"
# create data_items
for row in rows:
for col in row:
self.data_items.append(col)

那么如何最初创建具有位置值的 UI 数据表呢?

我想通了,首先我必须获取 init(这是加载表的位置)部分中的所有内容并将其放置在方法中。因此,我所要做的就是在单击按钮后从窗口中调用此方法 login.py 因此当用户到达管理页面数据时,数据已经新鲜加载。

最新更新