gpt4 book ai didi

python-3.x - Kivy:已弃用功能的替代方案

转载 作者:行者123 更新时间:2023-12-02 20:47:49 28 4
gpt4 key购买 nike

我正在尝试适应这个code但我仍然是第一步,因为我不理解大多数类似 SelectableDataItem 的功能。 , Adapter , ListAdapterSelectableView

当我在 kivy 网站上查找它们时,我发现它们被列为已弃用。我在 Kivy 网站上找不到这些功能的任何替代品,并且我不想构建具有已弃用功能的应用程序。

所以我的问题是:这四个功能的替代品是什么,或者换句话说,我应该如何修改代码,以便它不会调用已弃用的功能。

最佳答案

看看RecycleView
我用 RecycleView 写了一个您可能想要的示例

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.recycleview import RecycleView
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
from kivy.uix.recycleview.views import RecycleDataViewBehavior



items = [
{"text": "white", "selected": 'normal', "input_data": ["some","random","data"]},
{"text": "lightblue","selected": 'normal', "input_data": [1,6,3]},
{"text": "blue", "selected": 'normal', "input_data": [64,16,9]},
{"text": "gray", "selected": 'normal', "input_data": [8766,13,6]},
{"text": "orange", "selected": 'normal', "input_data": [9,4,6]},
{"text": "yellow", "selected": 'normal', "input_data": [852,958,123]},
{"text": "white", "selected": 'normal', "input_data": ["some","random","data"]},
{"text": "lightblue","selected": 'normal', "input_data": [1,6,3]},
{"text": "blue", "selected": 'normal', "input_data": [64,16,9]},
{"text": "gray", "selected": 'normal', "input_data": [8766,13,6]},
{"text": "orange", "selected": 'normal', "input_data": [9,4,6]},
{"text": "yellow", "selected": 'normal', "input_data": [852,958,123]}
]



class MyViewClass(RecycleDataViewBehavior, BoxLayout):

text = StringProperty("")
index = None

def set_state(self,state,app):
app.root.ids.rv.data[self.index]['selected'] = state

def refresh_view_attrs(self, rv, index, data):
self.index = index
return super(MyViewClass, self).refresh_view_attrs(rv, index, data)



class MyRecycleView(RecycleView):

data = items

def print_data(self,data):
print([item['input_data'] for item in data if item['selected'] == 'down'])



KV = '''

<MyViewClass>:
orientation: 'horizontal'
CheckBox:
on_state: root.set_state(self.state,app)
Label:
text: root.text

BoxLayout:
orientation: 'vertical'
MyRecycleView:
id: rv
viewclass: 'MyViewClass'
RecycleBoxLayout:
orientation: 'vertical'
default_size: None, dp(56)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
Button:
size_hint_y: 0.1
text: "Print data"
on_release: rv.print_data(rv.data)

'''



class Test(App):
def build(self):
root = Builder.load_string(KV)
return root


Test().run()

关于python-3.x - Kivy:已弃用功能的替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43561532/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com