python - 访问 StringProperty 数据并使用它 (KIVY)
问题描述
首先我想指出的是,我已经检查了许多类似的问题,这些问题最终使用StringProperty()
这些问题似乎只有在按钮的 on_release 或与其他 UI 小部件交互之后访问其中的数据时才能按预期工作。
我能够在屏幕登录中获取字符串属性并成功为其设置数据,如下所示
登录.py
self.parent.parent.parent.admin_widget.mylocation = str(self.ulocation) #DAta from textinput
这里我的 admin.py 文件如下所示: 我只是启动字符串属性,现在我有一个方法get_users
,该方法有一个 DataTable 并将小部件添加到屏幕,问题是最初加载时字符串属性为空,稍后在 textinput 提交后更新,我希望更改屏幕应该调用 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 窗口调用此方法,因此当用户访问管理页面时,数据已经被重新加载。
推荐阅读
- java - 如何使用 JDBC 插入局部变量 MySQL
- javascript - Mongo 文档中的更新数组不起作用
- mysql - 计算行之间的日期时间
- ruby-on-rails - 我面临一个关于 postgresql 的问题
- php - 使用 Laravel,我在通知颤振应用程序时收到以下错误
- kubernetes - 如何在 Kubernetes 部署配置中为主机名起别名
- python - 用 numpy 求解 Gram 矩阵上的线性方程
- android - WebView 不加载 Instagram 登录页面
- sql - ORA-01403: 从 INSERT 触发器中找不到数据
- python - PyCharm 上未解决的参考“rasa_nlu”