请检查以下程序为何给出
EncodedImage placeholder = (EncodedImage) initForm.theme.getImage("avater.png");
icon1 = URLImage.createToStorage(placeholder, "tyrion", "https://www.dropbox.com/s/52tu8jkqg1pikvw/jpeg?dl=1");
.py:
AttributeError: 'super' object has no attribute '__getattr__'
.kv:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ListProperty, NumericProperty, ObjectProperty
from kivy.uix.recycleview.views import RecycleDataViewBehavior
from kivy.uix.textinput import TextInput
# from kivy.effects.scroll.ScrollEffect import ScrollEffect
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.gridlayout import GridLayout
from kivy.uix.recycleboxlayout import RecycleBoxLayout
Builder.load_file('so_extractTIC.kv')
class RecycleItem(ScreenManager,RecycleDataViewBehavior, TextInput):
index = NumericProperty(0)
def refresh_view_attrs(self, rv, index, data):
self.index = index
return super(RecycleItem, self).refresh_view_attrs(rv, index, data)
class DataView(Screen):
DataList = ListProperty()
TextInputNum = NumericProperty(10)
def __init__(self,*args,**kwargs):
super(DataView, self).__init__(*args,**kwargs)
# for key, val in self.ids.items():
# print("key={0}, val={1}".format(key, val))
data12= []
for x in range(self.TextInputNum):
data12.append({'text': '', 'height': 50})
self.ids.rv.data = data12
def extract_data(self,rv):
print(self.parent.parent.parent)
self.DataList.clear()
for x in range(self.TextInputNum):
self.DataList.append(self.ids.rv.data[x]['text'])
print(self.DataList)
class RootWidget(ScreenManager):
pass
class MainApp(App):
def build(self):
# self.root = Builder.load_string(APP_KV)
return RootWidget()
if __name__ == '__main__':
MainApp().run()
我一直在搜索使用textInput框从recycleview提取数据。请找到查询链接:
Retrieve Data from Kivy Recycleview
我正在尝试从ScreenManager继承,但是它给出了'super'属性错误。尝试在.kv中将id作为参数传递,并尝试找到真正的父对象,但无济于事。
另外,请提出如何使用上面的代码来回收GridLaout的二维行和列,我尝试使用for循环,但是遇到了与键有关的错误。 喜欢:
<DataView>:
BoxLayout:
orientation: 'vertical'
RecycleView:
size_hint_y: 0.9
viewclass: 'RecycleItem'
id: rv
key_size: 'size'
# effect_cls: ScrollEffect
cols: 1
RecycleBoxLayout:
id: rvbox
cols: rv.cols
orientation: 'vertical'
size_hint_y: None
height: self.minimum_height
default_size_hint: 1, None
Button:
text: 'Submit'
size_hint_y: 0.1
on_release: root.extract_data()
<RecycleItem>:
on_text: self.parent.parent.data[self.index]['text'] = self.text
<RootWidget>:
DataView:
name:"DataView_screen"
谢谢!
答案 0 :(得分:0)
在您的DataView
类中,__init__()
方法引用了self.ids
,但此时ids
尚不可用。您可以像这样使用Clock.schedule_once()
来延迟引用:
def __init__(self, *args, **kwargs):
super(DataView, self).__init__(*args, **kwargs)
# for key, val in self.ids.items():
# print("key={0}, val={1}".format(key, val))
Clock.schedule_once(self.setup_data)
def setup_data(self, dt):
data12 = []
for x in range(self.TextInputNum):
data12.append({'text': '', 'height': 50})
self.ids.rv.data = data12
我没有理由将RecycleItem
设为ScreenManager
的子类。
在您的'kv , the
on_text line for
RecycleItem`中可以是:
<RecycleItem>:
on_text: app.root.get_screen('DataView_screen').ids.rv.data[self.index]['text'] = self.text
提交Button
可以是:
Button:
text: 'Submit'
size_hint_y: 0.1
on_release: root.extract_data(rv)