我试图在recycleview.But中添加按钮、标签和图像--运行代码时屏幕保持为黑色。我看不见我的纽扣。我要我的kv.file的作品..。我的意思是,我想将按钮、标签和图像从我的kv.file添加到循环视图(Boxlayout或Gridlayout)中。
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.config import Config
from kivy.properties import StringProperty
from kivy.uix.recycleview import RecycleView
from kivy.uix.recycleboxlayout import RecycleBoxLayout
Config.set('graphics', 'width', 360)
Config.set('graphics', 'height', 640)
kv= Builder.load_file('test5.kv')
#Define a RecycleView
class RV (RecycleView):
pass
class AwesomeApp(App):
def build(self):
return RV()
if __name__ == '__main__':
AwesomeApp().run()kv.file
<RV>:
viewclass: 'Button'
RecycleBoxLayout:
default_size: None,100
default_size_hint: 1, None
size_hinty:None
height: self.minimum_height
orientation:'vertical'
Button:
text:"test1"
Button:
text:"test2"
Label:
text: "text3"发布于 2022-04-06 18:22:49
有几件事是不对的。
首先,您是size_hinty变量,应该编写size_hint_y。
第二,您的小部件属性需要添加到RecycleView.data中。
尝试从<RV>类中删除.kv文件中的按钮,并将self.data添加到.py文件中的RV类中。这就是:
class RV(RecycleView):
def __init__(self, **kwargs):
super(RV, self).__init__(**kwargs)
self.data = [{'text': f'test{x}'} for x in range(1, 4)]https://stackoverflow.com/questions/71771582
复制相似问题