python - Python:换屏的简单函数
问题描述
我想通过更改屏幕的通用功能来减少我的代码。我的屏幕名称为数字,例如名称:“2”..当您单击底部表格中的某个列表时,我想更改某个屏幕。
在.py
def show_bottom_sheet(self):
bs = MDListBottomSheet()
bs.add_item("Models", lambda x: x,icon='account-group-outline')
for y in 1,2,3,4,12,13,14,21,23,24,31,32,34,41,42,43,123,124,134,234:
bs.add_item(f"example {y} ", lambda x= y: self.behavior(x), icon='account-group-outline')
bs.open()
def behavior(self, x):
self.manager.current = str(x)
在我改变之前是这样的,但是对于每一个数字,它太长了
def behavior2(self):
self.manager.current = "2"
我该如何解决?
解决方案
这是一种方法:
def show_bottom_sheet(self):
bs = MDListBottomSheet()
bs.add_item("Models", lambda x: x, icon='account-group-outline')
for y in 1, 2, 3, 4, 12, 13, 14, 21, 23, 24, 31, 32, 34, 41, 42, 43, 123, 124, 134, 234:
bs.add_item(f"example {y} ", partial(self.behavior, y), icon='account-group-outline')
bs.open()
def behavior(self, x, instance):
self.manager.current = str(x)
推荐阅读
- javascript - 在整个代码中的特定元素之后按类查找下一个元素(jQuery)
- empirical-lang - 试图在 OSX 上构建,但出现“没有规则来制作目标 antlr4_static”错误
- python - 用于捕获部分字符串的正则表达式
- webpack - Windows 上的 sw-precache-webpack-plugin - 无法解析窗口
- c# - 使用 Unity JsonUtility 反序列化 JSON 数组无法获取序列化值
- amazon-web-services - Best Way to manage AWS Access key ? So that when an employee leave the company . The employ should not be able to access the AWS account
- python - 如何使用枕头的 python 库实现图像通道删除
- mysql - 是否可以在 Mysql 中获取列名?
- python - setup.py install_requires 查找本地 src 包
- node.js - 如何将原始 JavaScript 代码写入 Node.js 中的文件?