Answer the question
In order to leave comments, you need to log in
How to display an image in a list?
When pushing a GridLayout into a ScrollView (an element to scroll), images are not displayed. What is the problem?
Images are in the same folder with .py, they are, their names are from 0.jpg to 13. If they are not, then empty squares are displayed where they should be (as they should be).
import kivy
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.scrollview import ScrollView
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image,AsyncImage
from kivy.uix.label import Label
class MyApp(App):
def build(self):
layout=GridLayout(cols=1, rows=0, padding=30, spacing=100, width=500, size_hint=(None, None))
layout.bind(minimum_height=layout.setter('height'))
#счетчик изображений
i=0
#цикл заполнения
i12=0
while i12<7:
#название категории
lblcat = Label(text='Название категории')
layout.rows+=1
layout.add_widget(lblcat)
#цикл добавления товаров в категорию
i13 = 0
while i13<2:
#загрузка изображения
img=Image(source=str(i)+'.jpg', id=str(i))
layout.rows+=1
layout.add_widget(img)
#название пикчи
lbl=Label(text='Предмет')
layout.rows+=1
layout.add_widget(lbl)
i+=1
i13+=1
i12+=1
root=ScrollView(size_hint=(None, None), size=(720, 480),pos_hint={'center_x': .5, 'center_y': .5}, do_scroll_x=False)
root.add_widget(layout)
return root
if __name__ == '__main__':
MyApp().run()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question