How in can gridlayout limit the number of rows for widgets to two, if there can be many more widgets?

134 views
Skip to first unread message

ТН Н

unread,
Feb 8, 2021, 8:08:03 PM2/8/21
to Kivy users support
The problem is that I can have hundreds of widgets, and so that their size is not tiny, I want to limit them to two on one screen, and to see the rest, you need to swipe down.

Elliot Garbus

unread,
Feb 9, 2021, 9:35:39 AM2/9/21
to kivy-...@googlegroups.com

It is not exactly clear to me what you are trying to do.

If you want to display hundreds of widgets, you should use a RecycleView. 

The use a RecycleBoxLayout to hold the viewclass. Set the orientation to vertical.

You want a viewclass that is derived from a GridLayout and set if to 1 row and 2 cols, or use a BoxLayout that holds 2 widgets.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/506c55c0-001e-4c6a-942e-70696a8043b7o%40googlegroups.com.

 

ТН Н

unread,
Feb 9, 2021, 10:18:25 AM2/9/21
to Kivy users support
Oh, I'm so stupid... I don't understand how to set this up. Could you please help me? Here is my test code.
from kivy.app import App
from kivy.lang import Builder
from kivy.metrics import dp
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.recycleview import RecycleView
from kivy.uix.recyclegridlayout import RecycleGridLayout
from kivy.uix.screenmanager import Screen, ScreenManager, NoTransition


Builder.load_string('''
<Start>:
    ric: ric
    RecycleGridLayout:
        id: ric
        Label:
            text: root.add()
   
                   


'''
)


class Start(Screen):
   
def add(self):
       
for i in range(50):
            lbl
= Label(text=str(i))
           
self.ids.ric.add_widget(lbl)
       
return 'one'


sm
= ScreenManager(transition = NoTransition())
sm
.add_widget(Start(name = 'one'))


class MagApp(App):
   
def build(self):
       
return sm
       
MagApp().run()

And I get all the widgets in the bottom left corner. What am I doing wrong?
вторник, 9 февраля 2021 г., 17:35:39 UTC+3 пользователь ElliotG написал:

It is not exactly clear to me what you are trying to do.

If you want to display hundreds of widgets, you should use a RecycleView. 

The use a RecycleBoxLayout to hold the viewclass. Set the orientation to vertical.

You want a viewclass that is derived from a GridLayout and set if to 1 row and 2 cols, or use a BoxLayout that holds 2 widgets.

 

 

From: ТН Н
Sent: Monday, February 8, 2021 6:08 PM
To: Kivy users support
Subject: [kivy-users] How in can gridlayout limit the number of rows forwidgets to two, if there can be many more widgets?

 

The problem is that I can have hundreds of widgets, and so that their size is not tiny, I want to limit them to two on one screen, and to see the rest, you need to swipe down.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Elliot Garbus

unread,
Feb 9, 2021, 10:58:46 AM2/9/21
to kivy-...@googlegroups.com

Here is an example:

 

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, ListProperty

kv =
'''
<TwoButtons>:
    Button:
        text: root.left_text
        on_release: print(f'Button {self.text} pressed')
    Button:
        text: root.right_text
        on_release: print(f'Button {self.text} pressed')
        
BoxLayout:
    RV:
        viewclass: 'TwoButtons'
        data: self.rv_data_list
        RecycleBoxLayout:
            default_size: None, dp(500)
            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height
            orientation: 'vertical'
'''


class TwoButtons(BoxLayout):
   left_text = StringProperty()
    right_text = StringProperty()


class RV(RecycleView):
    rv_data_list = ListProperty()

   
def __init__(self, **kwargs):
       
super().__init__(**kwargs)
       
self.rv_data_list = [{'left_text': f'Left {i}', 'right_text': f'Right {i}'} for i in range(200)]


class RVTwoApp(App):
   
def build(self):
       
return Builder.load_string(kv)


RVTwoApp().run()

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/3eee5759-6f59-4798-b72f-97f2ee855e9do%40googlegroups.com.

 

ТН Н

unread,
Feb 9, 2021, 11:08:09 AM2/9/21
to Kivy users support
Thanks. True, I don't understand anything, you need to somehow figure it out and tie it to your code, but that's my problem, you can't help. Thank you again.

вторник, 9 февраля 2021 г., 18:58:46 UTC+3 пользователь ElliotG написал:

Elliot Garbus

unread,
Feb 9, 2021, 11:51:58 AM2/9/21
to kivy-...@googlegroups.com

Here is a little help.

 

The Recyleview only creates the widgets that are visible and recycles them.  This makes it perform well when dealing with a large number of widgets.  The viewclass objects get instanced to create the objects in the RecycleView.  The data attribute, in the example set to rv_data_list, is used populate the widget with data, the 2 text items. The data attribute is a list of dictionaries.

 

https://kivy.org/doc/stable/api-kivy.uix.recycleview.html

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/b390c432-d737-4bc1-803a-3201736ae5e1o%40googlegroups.com.

 

ТН Н

unread,
Feb 9, 2021, 12:29:51 PM2/9/21
to Kivy users support
I have almost understood what you have written, but it is not enough for me. In my case, it's not just the label and buttons that need the text. In my example, I initially put a floatlayout with its own set of buttons, label, and images in a gridlayout. But there was a problem that this topic is dedicated to. I am quite a beginner or rather inattentive when studying the material, so for me everything you have written is unclear, not my level, it is beyond my capabilities at the moment. I could ask you to explain almost every line of your code in detail, but that would be too brazen of me. You've already done too much for me for nothing.

вторник, 9 февраля 2021 г., 19:51:58 UTC+3 пользователь ElliotG написал:

ТН Н

unread,
Feb 9, 2021, 1:18:20 PM2/9/21
to Kivy users support
This is a bad tone, i still need to understand, not copy, but please help me adapt this to my code. I made this entry, here the list is obtained from another database file, but the following error occurs: AttributeError: 'str' object has no attribute 'get'. I'm pretty sure it returns a list, not a string.

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, ListProperty
from BD import BD

kv = '''
<TwoButtons>:
    FloatLayout:
        Image:
            source: root.left_text
            pos_hint:{'
x': 0, 'y': .5}
            size_hint:(1, 1)
           
        ???
       
BoxLayout:
    RV:
        viewclass: '
TwoButtons'

        data: self.rv_data_list
        RecycleBoxLayout:
            default_size: None, dp(500)
            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height
            orientation: '
vertical'
'''





class TwoButtons(BoxLayout):
    left_text
= StringProperty()


class RV(RecycleView):
    rv_data_list
= ListProperty()


   
def __init__(self, **kwargs):
       
super().__init__(**kwargs)

        a
= BD()
        b
= a.get('path')
       
self.rv_data_list = b


class RVTwoApp(App):
   
def build(self):
       
return Builder.load_string(kv)




RVTwoApp().run()
I can count on you, can't I?" If not, then say so, I don't want to be intrusive. If you help, I will explain - where are the three question marks, there I do not understand how to add a button, a label, because they need a separate list. And here is the database code.
import sqlite3

class BD():
   
def add_to_bd(a, naz, about, path, price):
        db
= sqlite3.connect('server.db')
        sql
= db.cursor()
       
        sql
.execute('''CREATE TABLE IF NOT EXISTS magaz(naz TEXT, about TEXT, path TEXT, price INT)''')
        db
.commit()
       
        sql
.execute(f'SELECT naz and about and path FROM magaz WHERE naz = "{naz}" and about = "{about}" and path = "{path}"')
       
if sql.fetchone() is None:
            sql
.execute(f'INSERT INTO magaz VALUES(?, ?, ?, ?)',(naz, about, path, price))
            db
.commit()
       
else:
           
None
           
       
for val in sql.execute('SELECT * FROM magaz'):
           
print(val)
           
   
def get(a,name):
        db
= sqlite3.connect('server.db')
        sql
= db.cursor()
       
        spis
= []
       
for i in sql.execute(f'SELECT {name} FROM magaz'):
            spis
.append(i)
        k
= []
       
for i in range(len(spis)):
           
for j in spis[i]:
               
if j == ',':
                   
pass
               
elif j == '(':
                   
pass
               
elif j == ')':
                   
pass
               
else:
                    k
.append(j)
       
return k


   
#def delete():
   
#    db = sqlite3.connect('server.db')
   
#    sql = db.cursor()
   
#    
   
#    d = []
   
#    for val in sql.execute('SELECT naz FROM magaz'):
   
#        d.append(val)
   
#    
   
#    k = []
   
#    for i in range(len(d)):
   
#        for j in d[i]:
   
#            if j == ',':
   
#                pass
   
#            elif j == '(':
   
#                pass
   
#            elif j == ')':
   
#                pass
   
#            else:
   
#                k.append(j)
   
#    
   
#    for i in range(len(d)):
   
#        sql.execute(f'DELETE FROM magaz WHERE naz = "{k[i]}"')
   
#        db.commit()
       


вторник, 9 февраля 2021 г., 19:51:58 UTC+3 пользователь ElliotG написал:

Elliot Garbus

unread,
Feb 9, 2021, 2:03:26 PM2/9/21
to kivy-...@googlegroups.com
I’ll take a look later today. 

Sent from my iPhone

On Feb 9, 2021, at 11:19 AM, ТН Н <hatsune...@gmail.com> wrote:


To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/2fa1a708-77ec-4ab3-b874-9857dba35dd8o%40googlegroups.com.

Elliot Garbus

unread,
Feb 9, 2021, 4:29:11 PM2/9/21
to kivy-...@googlegroups.com

Lets start by reviewing the example, after you understand the example, you will be able to extend it to meet your needs.  I have added comments to the code.

Notice how the rv_data list is a list of dictionaries, and that the keys of the dictionary are the names of the TwoButtons (the viewclass) attributes.  The data associated with these keys gets assigned to the widgets.  Feel free to ask more questions.

 

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, ListProperty

kv =
'''
<TwoButtons>:
# This class is used as the viewclass in the RecycleView
# The means this widget will be instanced to view one element of data from the data list.
# The RecycleView data list is a list of dictionaries.  The keys in the dictionary specify the
# attributes of the widget.
    Button:
       text: root.left_text  # This data comes from the rv_data_list

        on_release: print(f'Button {self.text} pressed')
    Button:
        text: root.right_text  # This data comes from the rv_data_list

        on_release: print(f'Button {self.text} pressed')
        
BoxLayout:
    RV:                          # A Reycleview
        viewclass: 'TwoButtons'  # The view class is TwoButtons, defined above.
        data: self.rv_data_list  # the data is a list of dicts defined below in the RV class.
        RecycleBoxLayout:       
            # This layout is used to hold the Recycle widgets
            default_size: None, dp(500)   # This sets the height of the BoxLayout that holds a TwoButtons instance.

            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height   # To scroll you need to set the layout height.
            orientation: 'vertical'
'''


class TwoButtons(BoxLayout):        # The viewclass definitions, and property definitions.
   
left_text = StringProperty()
    right_text = StringProperty()


class RV(RecycleView):
   rv_data_list = ListProperty()    
# A list property is used to hold the data for the recycleview, see the kv code

   
def __init__(self, **kwargs):
       
super().__init__(**kwargs)
       
self.rv_data_list = [{'left_text': f'Left {i}', 'right_text': f'Right {i}'} for i in range(200)]
       
# This list comprehension is used to create the data list for this simple example.
        # The data created looks like:
        # [{'left_text': 'Left 0', 'right_text': 'Right 0'}, {'left_text': 'Left 1', 'right_text': 'Right 1'},
        # {'left_text': 'Left 2', 'right_text': 'Right 2'}, {'left_text': 'Left 3'},...
        # notice the keys in the dictionary corrospond to the kivy properties in the TwoButtons class.
        # The data needs to be in this kind of list of dictionary formats.  The RecycleView instances the
        # widgets, and populates them with data from this list.
   


ТН Н

unread,
Feb 10, 2021, 8:03:55 AM2/10/21
to Kivy users support
OK, you may have already described this, but I missed this point, however, my first question is: how can the button text be obtained from the left_text variable, which is an instance of some kivy class, but nevertheless, it somehow gets data from the rv_data_list list

среда, 10 февраля 2021 г., 0:29:11 UTC+3 пользователь ElliotG написал:

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

ТН Н

unread,
Feb 10, 2021, 10:18:08 AM2/10/21
to Kivy users support
I've already started to understand a lot more, but what am I doing wrong, trying to bring this closer to my code?

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, ListProperty
from BD import BD


kv
= '''
<TwoButtons>:
    FloatLayout:
        Image:
            source: root.left_text
            pos_hint:{'
x': 0, 'y
': .5}
            size_hint:(1, 1)
           
        Button:
            text: root.left_naz
            pos_hint:{'
x': .35,'y': .8}
            size_hint: .3, .1
           


    FloatLayout:
        Image:
            source: root.right_text
            pos_hint:{'
x': 0, 'y': .5}
            size_hint:(1, 1)
           
        Button:
            text: root.right_naz
            pos_hint:{'
x': .35,'y': .8}
            size_hint: .3, .1
           
BoxLayout:
    RV:
        viewclass: '
TwoButtons'

        data: self.rv_data_list
        RecycleBoxLayout:
            default_size: None, dp(500)
            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height
            orientation: '
vertical'
'''





class TwoButtons(BoxLayout):
    left_text
= StringProperty()
    right_text
= StringProperty()

    left_naz
= StringProperty()
    right_naz
= StringProperty()



class RV(RecycleView):
    rv_data_list
= ListProperty()


   
def __init__(self, **kwargs):
       
super().__init__(**kwargs)
        a
= BD()
        b
= a.get('path')

        c
= a.get('naz')
       
self.rv_data_list = [{'left_text': b[i], 'right_text': b[i]}, {'left_naz': c[i], 'right_naz': c[i]} for i in range(len(b))]



class RVTwoApp(App):
   
def build(self):
       
return Builder.load_string(kv)




RVTwoApp().run()

среда, 10 февраля 2021 г., 0:29:11 UTC+3 пользователь ElliotG написал:

Lets start by reviewing the example, after you understand the example, you will be able to extend it to meet your needs.  I have added comments to the code.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Elliot Garbus

unread,
Feb 10, 2021, 10:52:57 AM2/10/21
to kivy-...@googlegroups.com

You data list has an issue:

self.rv_data_list = [{'left_text': b[i], 'right_text': b[i]}, {'left_naz': c[i], 'right_naz': c[i]} for i in range(len(b))]

You have 2 dicts in the list, make it one dictionary:

 

self.rv_data_list = [{'left_text': b[i], 'right_text': b[i], 'left_naz': c[i], 'right_naz': c[i]} for i in range(len(b))]

 

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/a1f7270c-9d55-4cc3-af1b-dcc4dae1f3ado%40googlegroups.com.

 

ТН Н

unread,
Feb 10, 2021, 11:18:24 AM2/10/21
to Kivy users support
Okay, I get it. What about my previous question? And I still have a question, how does the process of distributing i in the for loop work? How is it that everything has its own numbers, not all, say, one.

среда, 10 февраля 2021 г., 18:52:57 UTC+3 пользователь ElliotG написал:

ТН Н

unread,
Feb 10, 2021, 11:22:59 AM2/10/21
to Kivy users support
Hmm, the names are duplicated. I have only two items in the list, but 4 widgets are created, the first pair has the name of the first element of the list, the second pair has the second name.


среда, 10 февраля 2021 г., 18:52:57 UTC+3 пользователь ElliotG написал:

You data list has an issue:

ТН Н

unread,
Feb 10, 2021, 11:26:08 AM2/10/21
to Kivy users support
If you add a third item to the list, the problem is the same - two more identical widgets are created.


среда, 10 февраля 2021 г., 18:52:57 UTC+3 пользователь ElliotG написал:

You data list has an issue:

Elliot Garbus

unread,
Feb 10, 2021, 12:06:46 PM2/10/21
to kivy-...@googlegroups.com

Replace the calls to BD.a

        b = a.get('path')
        c
= a.get('naz')

with lists that represent the data you expect so I can run the example. Without the database.

                   b = [‘path1’, ‘path2’]

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/237d5ee4-c524-43ac-9d6f-3380cccb65f5o%40googlegroups.com.

 

Message has been deleted
Message has been deleted

ТН Н

unread,
Feb 10, 2021, 12:31:16 PM2/10/21
to Kivy users support

       
#b = a.get('path')
       
#c = a.get('naz')
        b
= ['C:/...', 'D:/...'] #Here is the path to any images on the PC
        c
= ['Jackson', 'Mari']
       
self.rv_data_list = [{'left_text': b[i], 'right_text': b[i], 'left_naz': c[i], 'right_naz': c[i]} for i in range(len(c))]



class RVTwoApp(App):
   
def build(self):
       
return Builder.load_string(kv)




RVTwoApp().run()


среда, 10 февраля 2021 г., 20:06:46 UTC+3 пользователь ElliotG написал:

Elliot Garbus

unread,
Feb 10, 2021, 1:16:32 PM2/10/21
to kivy-...@googlegroups.com

There is some formatting problem that is causing things to not appear quite right – but this will get you closer to what I think you are looking for:

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, ListProperty
# from BD import BD

kv = '''
<TwoButtons>:
    FloatLayout:
        Button:
            # source: root.left_text
            text: root.left_text

            pos_hint:{'x': 0, 'y': .5}
            size_hint:(1, 1)
        Button:
            text: root.left_naz
            pos_hint:{'x': .35,'y': .8}
           size_hint: .3, .1


BoxLayout:
    RV:
        viewclass: 'TwoButtons'
        data: self.rv_data_list
        RecycleGridLayout:
            cols: 2

            default_size: None, dp(500)
            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height
'''


class TwoButtons(BoxLayout):
    left_text = StringProperty()
   
# right_text = StringProperty()
   
left_naz = StringProperty()
   
# right_naz = StringProperty()


class RV(RecycleView):
    rv_data_list = ListProperty()

   
def __init__(self, **kwargs):
       
super().__init__
(**kwargs)
       
# a = BD()
        # b = a.get('path')
        # c = a.get('naz')
       
b = ['a', 'b', 'c', 'd'# Here is the path to any images on the PC
        
c = ['Jackson', 'Mari', 'Robert', 'Sharon']
       
self.rv_data_list = [{'left_text': b[i], 'left_naz': c[i]} for i in range(len(c))]


        #b = a.get('path')

        #c = a.get('naz')

        b = ['C:/...', 'D:/...'] #Here is the path to any images on the PC

        c = ['Jackson', 'Mari'] 

        self.rv_data_list = [{'left_text': b[i], 'right_text': b[i], 'left_naz': c[i], 'right_naz': c[i]} for i in range(len(c))]

 

class RVTwoApp(App):

    def build(self):

        return Builder.load_string(kv)

 

 

RVTwoApp().run()


среда, 10 февраля 2021 г., 20:06:46 UTC+3 пользователь ElliotG написал:

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

ТН Н

unread,
Feb 10, 2021, 1:48:48 PM2/10/21
to Kivy users support
class RV(RecycleView):
    rv_data_list = ListProperty()

    def __init__(self, **kwargs):
        super().__init__
(**kwargs)# What's it? Of course, it gives an error, and if you remove it, then this is what it gives AttributeError: 'RV' object has no attribute '_disabled_count'
        # a = BD()
        b = ['a', 'b', 'c', 'd'] 
        c = ['Jackson', 'Mari', 'Robert', 'Sharon']
        self.rv_data_list = [{'left_text': b[i], 'left_naz': c[i]} for i in range(len(c))]

среда, 10 февраля 2021 г., 21:16:32 UTC+3 пользователь ElliotG написал:

ТН Н

unread,
Feb 10, 2021, 2:20:13 PM2/10/21
to Kivy users support
Oh, I wasn't paying attention. The error is fixed, everything works as it should.


среда, 10 февраля 2021 г., 21:16:32 UTC+3 пользователь ElliotG написал:

There is some formatting problem that is causing things to not appear quite right – but this will get you closer to what I think you are looking for:

ТН Н

unread,
Feb 10, 2021, 2:32:23 PM2/10/21
to Kivy users support
Okay, everything works. Now I can do what I want to do. But I still don't understand 2/3 of what I've written, despite your efforts.)


среда, 10 февраля 2021 г., 21:16:32 UTC+3 пользователь ElliotG написал:

There is some formatting problem that is causing things to not appear quite right – but this will get you closer to what I think you are looking for:

ТН Н

unread,
Feb 10, 2021, 2:40:30 PM2/10/21
to Kivy users support
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, ListProperty
from BD import BD


kv
= '''
<TwoButtons>:
    FloatLayout:
        Image:
            source: root.left_text
            pos_hint:{'
x': 0, 'y': .5}
            size_hint:(1, 1)
        Button:
            text: root.left_naz
            pos_hint:{'
x': .35,'y
': .8}
            size_hint: .3, .1




BoxLayout: #Why is there a boxlayout?
    RV: #What'
s it?

        viewclass
: 'TwoButtons'
        data
: self.rv_data_list
       
RecycleGridLayout:
            cols
: 2


            default_size
: None, dp(500)
            default_size_hint
: 1, None
            size_hint_y
: None
            height
: self.minimum_height
'''




class TwoButtons(BoxLayout):
    left_text = StringProperty() #What is this class? Why can'
t the image and button access the list directly?                                
    left_naz
= StringProperty() #How do they get information from it through this class?




class RV(RecycleView):
    rv_data_list
= ListProperty() #Is this mandatory? Why?



   
def __init__(self, **kwargs):
       
super().__init__(**kwargs)
        a
= BD()
        b
= a.get('path')
        c
= a.get('naz')

       
self.rv_data_list = [{'left_text': b[i], 'left_naz': c[i]} for i in range(len(c))]




class RVTwoApp(App):
   
def build(self):
       
return Builder.load_string(kv)




RVTwoApp().run()

среда, 10 февраля 2021 г., 21:16:32 UTC+3 пользователь ElliotG написал:

There is some formatting problem that is causing things to not appear quite right – but this will get you closer to what I think you are looking for:

Elliot Garbus

unread,
Feb 10, 2021, 4:08:33 PM2/10/21
to kivy-...@googlegroups.com

class TwoButtons(BoxLayout):
    left_text = StringProperty() #What is this class? Why can't the image and button access the list directly?                                
    left_naz = StringProperty() #How do they get information from it through this class?

These are kivy properties.  See: https://kivy.org/doc/stable/gettingstarted/properties.html,  https://kivy.org/doc/stable/api-kivy.properties.html?highlight=properties#module-kivy.properties

 

<TwoButtons>:
    FloatLayout:
        Image:
            source: root.left_text     # root is a reserve word in kv, it is referring to the instance of kivy StringProperty left_text defined in python.


            pos_hint:{'x': 0, 'y': .5}
            size_hint:(1, 1)
        Button:
            text: root.left_naz
            pos_hint:{'x': .35,'y': .8}
            size_hint: .3, .1

BoxLayout: #Why is there a boxlayout?

I chose this as the root widget.  It could have been a different layout.

 

RV: #What's it?
This is an instance of the recycleview, RV defined in Python.

 

class RV(RecycleView):
    rv_data_list = ListProperty() #Is this mandatory? Why?

A list is required.  The advantage of using a ListProperty is that if the Listproperty is updated, the View will automatically update.

 

Hope that helps.  FWIW – the Recycleview is an incredibly complex widget – with not quite complete documentation.

You can go and read some of the source code if you are interested.  There are some interesting techniques used. 

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/74fda010-6c4a-4719-bacc-9e9a93903e49o%40googlegroups.com.

 

ТН Н

unread,
Feb 10, 2021, 4:37:19 PM2/10/21
to Kivy users support
Yeah, it looks like I'll have to put off programming and learn English. I am very interested in all this, I would not sit here with questions if I knew English, but would go to read the documentation. Unfortunately, due to the translation curve, all your explanations are in vain, I did not understand anything.

четверг, 11 февраля 2021 г., 0:08:33 UTC+3 пользователь ElliotG написал:

ТН Н

unread,
Feb 10, 2021, 4:42:31 PM2/10/21
to Kivy users support
"BoxLayout: #Why is there a boxlayout?" I asked this because there is a recyclegridlayout at the bottom. The app actually uses gridlayout, so I don't quite understand the role of boxlayout


четверг, 11 февраля 2021 г., 0:08:33 UTC+3 пользователь ElliotG написал:

class TwoButtons(BoxLayout):

Elliot Garbus

unread,
Feb 10, 2021, 4:47:58 PM2/10/21
to kivy-...@googlegroups.com

The BoxLayout, in this case,  is the root widget.  It holds the recycleview, and the RecycleView holds the RecycleGridLayout.

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

ТН Н

unread,
Feb 10, 2021, 5:07:15 PM2/10/21
to Kivy users support
Please, view my code, i get error:  kivy.factory.FactoryException: Unknown class <RV>

from kivy.app import App
from kivy.lang import Builder
from kivy.metrics import dp
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.recycleview import RecycleView

from kivy.properties import StringProperty, ListProperty
from kivy.uix.screenmanager import Screen, ScreenManager, NoTransition
from BD import BD
import csv


Builder.load_string('''
<Start>:
    FloatLayout:
        Button:
            text: '
добавить'
            size_hint: .4, .08
            pos_hint:{'
center_x': .5, 'y': .8}
            on_release: root.manager.current = '
add'
           
        Button:
            text: '
посмотреть'
            size_hint: .4, .08
            pos_hint:{'
center_x': .5, 'y': .2}
            on_release: root.manager.current = '
mag'
           
<Add>:


    path: path
    naz: naz
    about: about
    price: price


    FloatLayout:
        Label:
            text: '
Абсолютный путь к изображению'
            size_hint: .4, .08
            pos_hint:{'
center_x': .5, 'y': .9}
           
        Label:
            text: '
Название'
            size_hint: .4, .08
            pos_hint:{'
center_x': .5, 'y': .7}
           
        Label:
            text: '
Описание'
            size_hint: .4, .08
            pos_hint:{'
center_x': .5, 'y': .5}
           
        Label:
            text: '
Цена'
            size_hint: .4, .08
            pos_hint:{'
center_x': .5, 'y': .3}
           
        TextInput:
            id: path
            size_hint: .8, .08
            pos_hint:{'
center_x': .5, 'y': .8}
           
        TextInput:
            id: naz
            size_hint: .8, .08
            pos_hint:{'
center_x': .5, 'y': .6}
           
        TextInput:
            id: about
            size_hint: .8, .08
            pos_hint:{'
center_x': .5, 'y': .4}
           
        TextInput:
            id: price
            size_hint: .8, .08
            pos_hint:{'
center_x': .5, 'y': .2}    
           
        Button:
            text: '
Добавить'
            size_hint: .4, .08
            pos_hint:{'
center_x': .2, 'y': .1}
            on_release: root.add()
           
        Button:
            text: '
Назад'
            size_hint: .4, .08
            pos_hint:{'
center_x': .8, 'y': .1}
            on_release: root.manager.current = '
one'
           
<Magaz>:
    FloatLayout:
        Image:
            source: root.img
            size_hint: 1, 1
            pos_hint:{'
x': 0, 'y': .5}
               
        Label:
            text: root.naz
            font_size: 20
            pos_hint:{'
x': 0,'y': .4}
                   
        Label:
            text: root.abt
            font_size: 15
            pos_hint:{'
x': 0,'y': .3}
                   
        Label:
            text: root.prc
            font_size: 15
            size_hint: .3, .1
            pos_hint:{'
x': .001,'y': .3}
                   
        Button:
            text: '
Купить'
            size_hint: .3, .1
            pos_hint:{'
x': .7,'y': .3}
            on_release: root.per()
           
BoxLayout:
    RV:
        viewclass: '
Magaz'
        data: self.rv_data

        RecycleGridLayout:
            cols: 2


            default_size: None, dp(500)
            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height
               
<See_tov>:
    BoxLayout:
       
        orientation: '
vertical'
       
        Image:
            source: root.see('
path')
           
        Label:
            text: root.see_name()
           
        Label:
            text: root.see('
about')
           
        Label:
            text: root.see('
price')
           
        Button:
            text: '
Купить'
           
        Button:
            text: '
Назад'
            on_release: root.manager.current = '
mag'
'''
)


class Start(Screen):
   
pass  
   
class Magaz(BoxLayout):
    img
= StringProperty()
    naz
= StringProperty()
    abt
= StringProperty()
    prc
= StringProperty()
       
   
def per(self, naz):
       
try:
            nazv
= naz.text
       
except:
            a
= open('naz.csv')
            b
= csv.reader(a)
            c
= next(b)
            d
= []
           
for i in c:
                d
.append(i)
           
return d[0]
       
else:
            a
= open('naz.csv','w')
            a
.write(nazv)
            a
.close()
            sm
.current = 'see'
           
class RV(RecycleView):


    rv_data
= ListProperty()

   
   
def __init__(self, **kwargs):
       
super().__init__(**kwargs)
        a
= BD()

        b
= a.get('path')
        c
= a.get('naz')

        d
= a.get('price')
        e
= a.get('about')
       
self.rv_data = [{'img': b[i], 'naz': c[i], 'prc': str(d[i]), 'abt': e[i]} for i in range(len(c))]


class Add(Screen):
   
def add(self):
        naz
= self.naz.text
        about
= self.about.text
        path
= self.path.text
        price
= self.price.text
        a
= BD()
        a
.add_to_bd(naz=naz, about=about, path=path, price=price)
       
class See_tov(Screen):
   
def see_name(self):
        a
= Magaz()
        b
= a.per(1)
       
return b
       
   
def see(self, nam):
        naz
= self.see_name()
        a
= BD()
        b
= a.get('naz')
        ind
= 0
       
for i in b:
           
if naz == i:
                ind
= b.index(i)
        bb
= a.get(nam)
        res
= bb[ind]
       
return str(res)

   
sm
= ScreenManager(transition = NoTransition())
sm
.add_widget(Start(name = 'one'))

sm
.add_widget(Magaz(name = 'mag'))
sm
.add_widget(Add(name = 'add'))
sm
.add_widget(See_tov(name = 'see'))



class MagApp(App):
   
def build(self):
       
return sm
       
MagApp().run()


четверг, 11 февраля 2021 г., 0:47:58 UTC+3 пользователь ElliotG написал:

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Elliot Garbus

unread,
Feb 10, 2021, 5:44:35 PM2/10/21
to kivy-...@googlegroups.com

User Builder.load_string(kv), as in the example I shared.

Move the Screenmanger code to kv.  You currently are defining a rootwidget in kv and a rootwidget in Python.

 

Convert this code to KV code:

sm = ScreenManager(transition = NoTransition())
sm.add_widget(Start(name = 'one'))
sm.add_widget(Magaz(name = 'mag'))
sm.add_widget(Add(name = 'add'))
sm.add_widget(See_tov(name = 'see'))

You have a BoxLayout as a root widget that holds the RecycleView…  Did you want this on a Screen?

And you have sm, the screenmanager as a root widget.  You can only have one root widget.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/c57a44dd-68b7-473c-889c-6cf2f9f8f4b0o%40googlegroups.com.

 

ТН Н

unread,
Feb 10, 2021, 5:59:10 PM2/10/21
to Kivy users support
"You have a BoxLayout as a root widget that holds the RecycleView…  Did you want this on a Screen?" -  So it was in your example, I just copied it.

четверг, 11 февраля 2021 г., 1:44:35 UTC+3 пользователь ElliotG написал:

ТН Н

unread,
Feb 10, 2021, 6:05:11 PM2/10/21
to Kivy users support
Hmm, so how do I make it so that the screen that I have specified in sm is initially shown and everything works the same way?


четверг, 11 февраля 2021 г., 1:44:35 UTC+3 пользователь ElliotG написал:

User Builder.load_string(kv), as in the example I shared.

Elliot Garbus

unread,
Feb 10, 2021, 6:10:00 PM2/10/21
to kivy-...@googlegroups.com

In KV

ScreenManger:

    Start:

        name: ‘one’

and add all the other screens and their respective names..

 

Then you need to decide where you want the RV.

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

ТН Н

unread,
Feb 10, 2021, 6:20:09 PM2/10/21
to Kivy users support
I apologize already for the frankly stupid questions, but how do I indicate that the RV should be in the Magaz

четверг, 11 февраля 2021 г., 2:10:00 UTC+3 пользователь ElliotG написал:

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

ТН Н

unread,
Feb 10, 2021, 6:21:23 PM2/10/21
to Kivy users support
And how then to change main.py


четверг, 11 февраля 2021 г., 2:10:00 UTC+3 пользователь ElliotG написал:

In KV

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Elliot Garbus

unread,
Feb 10, 2021, 6:26:47 PM2/10/21
to kivy-...@googlegroups.com

Magaz is your view class you can have it derived from a FloatLayout, and remove the FloatLayout line in the kv code.

 

The Create an MagazScreen  and put the RV on that Screen.  Don’t forget to update the screenmanager…

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/c4988bde-af1a-4a31-b5d2-2d1fea272e93o%40googlegroups.com.

 

ТН Н

unread,
Feb 11, 2021, 6:36:02 AM2/11/21
to Kivy users support
I apologize again. I've never worked with .kv file, I can't find the right one on the Internet. Is that what you meant?"

.kv

ScreenManager:
   
Start:
        name
: 'one'
       
   
Magaz:
        name
: 'mag'
       
   
Add:
        name
: 'add'
       
   
See_tov:
        name
: 'see'
main.py
<Magaz>:

    FloatLayout:
        Image:
            source: root.img
            size_hint: 1, 1
            pos_hint:{'x': 0, 'y': .5}
               
        Label:
            text: root.naz
            font_size: 20
            pos_hint:{'x': 0,'y': .4}
                   
        Label:
            text: root.abt
            font_size: 15
            pos_hint:{'x': 0,'y': .3}
                   
        Label:
            text: root.prc
            font_size: 15
            size_hint: .3, .1
            pos_hint:{'x': .001,'y': .8}
                   
        Button:
            text: 'Купить'
            size_hint: .3, .1
            pos_hint:{'x': .7,'y': .8}
            on_release: root.per()

           
        RV:
            viewclass: 'Magaz'
            data: self.rv_data
            RecycleGridLayout:
                cols: 2


                default_size: None, dp(500)
                default_size_hint: 1, None
                size_hint_y: None
                height: self.minimum_height

четверг, 11 февраля 2021 г., 2:10:00 UTC+3 пользователь ElliotG написал:

In KV

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Elliot Garbus

unread,
Feb 11, 2021, 9:25:44 AM2/11/21
to kivy-...@googlegroups.com

You don’t need to use a separate kv file, add the Screenmanager code to your kv string.

 

In your py file you want to do the Builder.load_string in the return of build…

 

kv = “””

ScreenManager:
   
Start:
        name
: 'one'
       
   
Magaz:
        name
: 'mag'
       
   
Add:
        name
: 'add'
       
   
See_tov:
        name
: 'see'

 

<Magaz>:


    FloatLayout:
        Image:
            source: root.img
            size_hint: 1, 1
            pos_hint:{'x': 0, 'y': .5}

    … and continue with all of your kv code….           

“””

 

And in build:

def build(self):

    return Builder.load_string(kv)

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/bc1be706-a819-435b-a323-94b319431a58o%40googlegroups.com.

 

ТН Н

unread,
Feb 11, 2021, 10:55:10 AM2/11/21
to Kivy users support
 What am I doing wrong? This entry returns an error. kivy.uix.screenmanager.ScreenManagerException: ScreenManager accepts only Screen widget.

kv = '''
ScreenManager:
    Start:
        name: '
one'
       
    Magaz:
        name: '
mag'
       
    Add:
        name: '
add'
       
    See_tov:
        name: '
see
'


...
x': 0, 'y': .5}
x': 0,'y': .4}
x': 0,'y': .3}
x': .001,'y': .8}
                   
        Button:
            text: '
Купить'
            size_hint: .3, .1
            pos_hint:{'
x': .7,'y': .8}
            on_release: root.per()
           
    RV:
        viewclass: '
Magaz'


четверг, 11 февраля 2021 г., 17:25:44 UTC+3 пользователь ElliotG написал:

            pos_hint:{'center_x': .5, 'y': .4}</spa

Elliot Garbus

unread,
Feb 11, 2021, 11:04:12 AM2/11/21
to kivy-...@googlegroups.com

Are Start, Magaz, Add, See_tov each derived from a Screen class?

Magaz is your view class – it should be on a Screen, it should not be a Screen.

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

ТН Н

unread,
Feb 11, 2021, 11:18:24 AM2/11/21
to Kivy users support
Then I need to make the initial entry like this?

ScreenManager:
   
Start:
        name
: 'one'

       
   
Add:
        name
: 'add'
       
   
See_tov:
        name
: 'see'
I'm sorry, I don't understand how to add it to the screen and how to record it at all and where.

четверг, 11 февраля 2021 г., 19:04:12 UTC+3 пользователь ElliotG написал:

    price: price<spa

Elliot Garbus

unread,
Feb 11, 2021, 11:24:22 AM2/11/21
to kivy-...@googlegroups.com

Magaz is your viewclass.  This is how your Recycleview displays data.

You currently have the RV in the Magaz class – this in not right.

I will assume you want to display the Magaz list on a screen, lets call that MagazScreen

Under the screen manager add the MagazScreen.

 

Create the MagazScreen…

<MagazScreen@Screen>: # or declare in python

    RV: … # all the details here…

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

ТН Н

unread,
Feb 11, 2021, 1:36:35 PM2/11/21
to Kivy users support
? Warning, too much iteration done before the next frame. Check your code, or increase the Clock

kv = '''
ScreenManager:
    Start:
        name: '
one'
    Magaz:
        name: '
mag'
    Add:
        name: '
add'
       
    See_tov:
        name: '
see'
<Magaz>:
    FloatLayout:
        Image:
            source: root.img
            size_hint: 1, 1
            pos_hint:{'
x': 0, 'y
': .5}
               
        Label:
            text: root.naz
            font_size: 20
            pos_hint:{'
x': 0,'y': .4}

                   
        Label:
            text: root.abt
            font_size: 15
            pos_hint:{'
x': 0,'y': .3}

                   
        Label:
            text: root.prc
            font_size: 15
            size_hint: .3, .1
            pos_hint:{'
x': .001,'y': .8}
                   
        Button:
            text: '
Купить'
            size_hint: .3, .1
            pos_hint:{'
x': .7,'y': .8}
            on_release: root.per()
<Magaz@Screen>:            
    RV:
        viewclass: '
Magaz'

        data: self.rv_data
        RecycleGridLayout:
            cols: 2


            default_size: None, dp(500)
            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height


четверг, 11 февраля 2021 г., 19:24:22 UTC+3 пользователь ElliotG написал:

            pos_hint:{'center_x': .5, 'y': .2}<span style='font-size:10.0pt;font-

Elliot Garbus

unread,
Feb 11, 2021, 5:33:15 PM2/11/21
to kivy-...@googlegroups.com

Share an executable program – there is not enough here to see the issue.

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

ТН Н

unread,
Feb 11, 2021, 5:54:09 PM2/11/21
to Kivy users support
Not new...

from kivy.app import App
from kivy.lang import Builder
from kivy.metrics import dp
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.recycleview import RecycleView
from kivy.properties import StringProperty, ListProperty
from kivy.uix.screenmanager import Screen, ScreenManager, NoTransition
from BD import BD
import
csv


kv
= '''
ScreenManager:
    Start:
        name: '
one'
    Magaz:
        name: '
mag'
    Add:
        name: '
add'
       
    See_tov:
        name: '
see'
       
<Start>:
    FloatLayout:
        Button:
            text: '
добавить'
            size_hint: .4, .08
            pos_hint:{'
center_x': .5, 'y': .8}
            on_release: root.manager.current = '
add'
           
        Button:
            text: '
посмотреть'
            size_hint: .4, .08
            pos_hint:{'
center_x': .5, 'y': .2}
            on_release: root.manager.current = '
mag' #And how do I call it?

           
<Add>:


    path: path
    naz: naz
    about: about
    price: price


    FloatLayout:
        Label:
            text: '
Абсолютный путь к изображению'
            size_hint: .4, .08
            pos_hint:{'
center_x': .5, 'y': .9}
           
        Label:
            text: '
Название'
            size_hint: .4, .08
            pos_hint:{'
center_x': .5, 'y': .7}
           
        Label:
            text: '
Описание'
            size_hint: .4, .08
            pos_hint:{'
center_x': .5, 'y': .5}
           
        Label:
            text: '
Цена'
            size_hint: .4, .08
            pos_hint:{'
center_x': .5, 'y': .3}
           
        TextInput:
            id: path
            size_hint: .8, .08
            pos_hint:{'
center_x': .5, 'y': .8}
           
        TextInput:
            id: naz
            size_hint: .8, .08
            pos_hint:{'
center_x': .5, 'y': .6}
           
        TextInput:
            id: about
            size_hint: .8, .08
            pos_hint:{'
center_x': .5, 'y': .4}
           
        TextInput:
            id: price
            size_hint: .8, .08
            pos_hint:{'
center_x': .5, 'y': .2}    
           
        Button:
            text: '
Добавить'
            size_hint: .4, .08
            pos_hint:{'
center_x': .2, 'y': .1}
            on_release: root.add()
           
        Button:
            text: '
Назад'
            size_hint: .4, .08
            pos_hint:{'
center_x': .8, 'y': .1}
            on_release: root.manager.current = '
one'
           
x': 0, 'y': .5}
x': 0,'y': .4}
x': 0,'y': .3}
x': .001,'y': .8}
                   
        Button:
            text: '
Купить'
            size_hint: .3, .1
            pos_hint:{'
x': .7,'y': .8}
Magaz'
<See_tov>:
    BoxLayout:
       
        orientation: '
vertical'
       
        Image:
            source: root.see('
path')

           
        Label:
            text: root.see_name()
           
        Label:
            text: root.see('
about')
           
        Label:
            text: root.see('
price')
           
        Button:
            text: '
Купить'
           
        Button:
            text: '
Назад'
            on_release: root.manager.current = '
mag'
'''



class Start(Screen):
   
pass  
   
class Magaz(Screen):
#sm = ScreenManager(transition = NoTransition())
#sm.add_widget(Start(name = 'one'))
#sm.add_widget(Magaz(name = 'mag'))
#sm.add_widget(Add(name = 'add'))
#sm.add_widget(See_tov(name = 'see'))


class MagApp(App):
   
def build(self):
       
return Builder.load_string(kv)
       
MagApp().run()


пятница, 12 февраля 2021 г., 1:33:15 UTC+3 пользователь ElliotG написал:

<span sty

Elliot Garbus

unread,
Feb 11, 2021, 7:09:57 PM2/11/21
to kivy-...@googlegroups.com

Commented out some code so I could run it.  You can fix those changes.  I also fixed a few things.

 

from kivy.app import App
from kivy.lang import Builder
from kivy.metrics import dp
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.recycleview import RecycleView
from kivy.properties import StringProperty, ListProperty
from kivy.uix.screenmanager import Screen, ScreenManager, NoTransition
# from BD import BD
import csv

kv =
'''
ScreenManager:
    Start:
        name: 'one'
    MagazScreen:
<MagazScreen@Screen>:            
class Start(Screen):
   
pass


class
Magaz(FloatLayout):  # Changed fron a screen - this is not a screen
   
img = StringProperty()

    naz = StringProperty()
    abt = StringProperty()
    prc = StringProperty()

   
def per(self, naz):
       
try:
           
nazv = naz.text
       
except:
           
# a = open('naz.csv')
            # b = csv.reader(a)
            # c = next(b)
            # d = []
            # for i in c:
            #     d.append(i)
            # return d[0]
           
return 'JUNK'
       
else:
           
# a = open('naz.csv', 'w')
            # a.write(nazv)
            # a.close()
            # sm.current = 'see'  # This refers to an undefined variable...sm
           
self.manager.current = 'see'


class RV(RecycleView):
    rv_data = ListProperty()

   
def __init__(self, **kwargs):
       
super().__init__
(**kwargs)
       
# a = BD()
        # b = a.get('path')
        # c = a.get('naz')
        # d = a.get('price')
        # e = a.get('about')
       
b = ['one', 'two', 'three']
        c = [
'one', 'two', 'three']
        d = [
'one', 'two', 'three']
        e = [
'one', 'two', 'three']


       
self.rv_data = [{'img': b[i], 'naz': c[i], 'prc': str(d[i]), 'abt': e[i]} for i in range(len(c))]


class Add(Screen):
   
def add(self):
       
naz = self.naz.text
       
about = self.about.text
       
path = self.path.text
       
price = self
.price.text
       
# a = BD()
        # a.add_to_bd(naz=naz, about=about, path=path, price=price)


class See_tov(Screen):
   
def see_name(self):
       
# a = Magaz()
        # b = a.per(1)
       
b = 'junk'
       
return b

   
def see(self, nam):
       
naz = self.see_name()
       
# a = BD()
        # b = a.get('naz')
        # ind = 0
        # for i in b:
        #     if naz == i:
        #         ind = b.index(i)
        # bb = a.get(nam)
        # res = bb[ind]
       
res = 'junk'
       
return str(res)


# sm = ScreenManager(transition = NoTransition())
# sm.add_widget(Start(name = 'one'))
# sm.add_widget(Magaz(name = 'mag'))
# sm.add_widget(Add(name = 'add'))
# sm.add_widget(See_tov(name = 'see'))


class MagApp(App):
   
def build(self):
       
return Builder.load_string(kv)


MagApp().run()

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

ТН Н

unread,
Feb 12, 2021, 5:21:52 AM2/12/21
to Kivy users support
OK, it works, I'm very grateful.

пятница, 12 февраля 2021 г., 3:09:57 UTC+3 пользователь ElliotG написал:

Not new...

 

<span class=s

ТН Н

unread,
Feb 15, 2021, 2:11:24 PM2/15/21
to Kivy users support
Dear Eliot, something broke and I had two problems:
1. Only one widget is displayed on the 'Magaz' screen, but there should be two of them.
2.You can't switch from the 'Magaz' screen to another one.
Here is the full code:

from kivy.app import App
from kivy.lang import Builder
from kivy.metrics import dp
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.recycleview import RecycleView
from kivy.properties import StringProperty, ListProperty
from kivy.uix.screenmanager import Screen, ScreenManager, NoTransition
#from BD import BD

import csv


kv
= '''
ScreenManager:
    Start:
        name: '
one'
    MagazScreen:
        name: '
mag'
    Add:
        name: '
add'
    See_tov:
        name: '
see'


<Start>:
    FloatLayout:
        Button:
            text: '
добавить'
            size_hint: .4, .08
            pos_hint:{'
center_x': .5, 'y': .8}
            on_release: root.manager.current = '
add'


        Button:
            text: '
посмотреть'
            size_hint: .4, .08
            pos_hint:{'
center_x': .5, 'y': .2}
            on_release: root.manager.current = '
mag
'

Абсолютный путь к изображению'
            size_hint: .4, .08
            pos_hint:{'
center_x': .5, 'y': .9}


        Label:
            text: '
Название'
            size_hint: .4, .08
            pos_hint:{'
center_x': .5, 'y': .7}


        Label:
            text: '
Описание'
            size_hint: .4, .08
            pos_hint:{'
center_x': .5, 'y': .5}


        Label:
            text: '
Цена'
            size_hint: .4, .08
            pos_hint:{'
center_x': .5, 'y': .3}
center_x': .5, 'y': .8}
center_x': .5, 'y': .6}
center_x': .5, 'y': .4}
center_x': .5, 'y': .2}    


        Button:
            text: '
Добавить'
            size_hint: .4, .08
            pos_hint:{'
center_x': .2, 'y': .1}
            on_release: root.add()


        Button:
            text: '
Назад'
            size_hint: .4, .08
            pos_hint:{'
center_x': .8, 'y': .1}
            on_release: root.manager.current = '
one'


<Magaz>:
    FloatLayout:
        #Image:
        #    source: root.img
        #    size_hint: 1, 1
        #    pos_hint:{'
x': 0, 'y': .5}



        Label:
            text: root.naz
            font_size: 20
            pos_hint:{'
x': 0,'y': .4}



        Label:
            text: root.abt
            font_size: 15
            pos_hint:{'
x': 0,'y': .3}



        Label:
            text: root.prc
            font_size: 15
            size_hint: .3, .1
            pos_hint:{'
x': .001,'y': .8}


        Button:
            text: '
Купить'
            size_hint: .3, .1
            pos_hint:{'
x': .7,'y': .8}
            #on_release: root.per()
           
<MagazScreen@Screen>:            
    RV:
        viewclass: '
Magaz'

        data: self.rv_data
        RecycleGridLayout:
            cols: 2
            default_size: None, dp(500)
            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height


<See_tov>:
    BoxLayout:


        orientation: '
vertical'


        #Image:
        #    source: root.see('
path')



        Label:
            text: root.see_name()


        Label:
            text: root.see('
about')


        Label:
            text: root.see('
price')


        Button:
            text: '
Купить'


        Button:
            text: '
Назад'
            on_release: root.manager.current = '
mag'
'''





class Start(Screen):
   
pass  
   
class Magaz(FloatLayout):

    img
= StringProperty()
    naz
= StringProperty()
    abt
= StringProperty()
    prc
= StringProperty()
       
   
def per(self, naz):
       
try:
            nazv
= naz.text
       
except:
           
#a = open('naz.csv')
           
#b = csv.reader(a)
           
#c = next(b)
           
#d = []

           
#for i in c:

           
#    d.append(i)
           
#return d[0]

           
self.manager.current = 'see'

       
else:
            a
= open('naz.csv','w')
            a
.write(nazv)
            a
.close()

           
self.manager.current = 'see'
           
class RV(RecycleView):


    rv_data
= ListProperty()
   
   
def __init__(self, **kwargs):
       
super().__init__(**kwargs)

        a
= BD()
       
#b = a.get('path')
       
#c = a.get('naz')

       
#d = a.get('price')
       
#e = a.get('about')
       
#b = ['a', 'b']
        c
= ['name1', 'name2']
        d
= ['43', '23']
        e
= ['little', 'big']
       
self.rv_data = [{'naz': c[i], 'prc': str(d[i]), 'abt': e[i]} for i in range(len(c))]



class Add(Screen):
   
def add(self):
        naz
= self.naz.text
        about
= self.about.text
        path
= self.path.text
        price
= self.price.text
        a
= BD()
        a
.add_to_bd(naz=naz, about=about, path=path, price=price)
       
class See_tov(Screen):
   
def see_name(self):
        a
= Magaz()
        b
= a.per(1)
       
return b
       
   
def see(self, nam):
        naz
= self.see_name()
        a
= BD()
        b
= a.get('naz')
        ind
= 0
       
for i in b:
           
if naz == i:
                ind
= b.index(i)
        bb
= a.get(nam)
        res
= bb[ind]
       
return str(res)


class MagApp(App):
   
def build(self):
       
return Builder.load_string(kv)
       
MagApp().run()


пятница, 12 февраля 2021 г., 3:09:57 UTC+3 пользователь ElliotG написал:

Not new...

 

<span class=s

Elliot Garbus

unread,
Feb 15, 2021, 3:52:12 PM2/15/21
to kivy-...@googlegroups.com

I have to comment a number things out to get the code to run. .

One thing I see:

def per(self, naz):
       
try:
            nazv
= naz.text  # looks like naz is expected to be a widget.

 

You are calling per with an int

class See_tov(Screen):
   
def see_name(self):
        a = Magaz()
       
b = a.per(1)

 

Changed Magz to be derived from a BoxLayout, and reduced the min size of the RecycleView Grid…

 

'''

            default_size: None, dp(200)


            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height


<See_tov>:
    BoxLayout:


        orientation: 'vertical'


        #Image:
        #    source: root.see('path')


        Label:
            text: root.see_name()


        Label:
            text: root.see('about')


        Label:
            text: root.see('price')


        Button:
            text: 'Купить'


        Button:
            text: 'Назад'
            on_release: root.manager.current = 'mag'
'''


class Start(Screen):
   
pass


class
Magaz(BoxLayout):


    img = StringProperty()
    naz = StringProperty()
    abt = StringProperty()
    prc = StringProperty()

   

def per(self, naz):
       
try:
            nazv = naz.text 
# your passing a int here...
       
except:
           
# a = open('naz.csv')


            # b = csv.reader(a)
            # c = next(b)
            # d = []
            # for i in c:
            #    d.append(i)
            # return d[0]

            self.manager.current = 'see'
       
else:
            a =
open('naz.csv', 'w')
            a.write(nazv)
            a.close()
           
self.manager.current = 'see'


class RV(RecycleView):
    rv_data = ListProperty()

   
def __init__(self, **kwargs):
       
super().__init__

(**kwargs)
       
# a = BD()


        # b = a.get('path')
        # c = a.get('naz')
        # d = a.get('price')
        # e = a.get('about')

        # b = ['a', 'b']
       
c = ['name1', 'name2','name3']
        d = [
'43', '23', '44']
        e = [
'little', 'big', 'next']
       
self.rv_data = [{'naz': c[i], 'prc': str(d[i]), 'abt': e[i]} for i in range(len(c))]


class Add(Screen):
   
def add(self):
       
naz = self.naz.text
       
about = self.about.text
       
path = self.path.text
       
price = self

.price.text
       
# a = BD()


        # a.add_to_bd(naz=naz, about=about, path=path, price=price)


class See_tov(Screen):
   
def see_name(self):
       
a = Magaz()
       
# b = a.per(1)
       
b = 'junk'
       
return b

   
def see(self, nam):
       
naz = self.see_name()
       
# a = BD()


        # b = a.get('naz')
        # ind = 0
        # for i in b:
        #     if naz == i:
        #         ind = b.index(i)
        # bb = a.get(nam)
        # res = bb[ind]

        res = 'JUNK'
       
return str(res)


class MagApp(App):
   
def build(self):
       
return Builder.load_string(kv)


MagApp().run()

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

ТН Н

unread,
Feb 16, 2021, 3:40:38 AM2/16/21
to Kivy users support
Hmm, it looks like it worked anyway, just that there should be at least three widgets to display correctly. But switching to another screen from the 'Magaz' screen still doesn't work, I get the error: AttributeError: the 'Magaz' object doesn't have the 'manager'attribute

class Magaz(BoxLayout):
    img
= StringProperty()
    naz
= StringProperty()
    abt
= StringProperty()
    prc
= StringProperty()

       
   
def per(self, naz): #Do not pay attention to how everything works here now, in the future everything will be correctly implemented here, now I need to solve the problem with the transition.

       
try:
            nazv
= naz.text
       
except:
           
#a = open('naz.csv')
           
#b = csv.reader(a)
           
#c = next(b)
           
#d = []
           
#for i in c:
           
#    d.append(i)
           
#return d[0]

           
self.manager.current = 'one'

       
else:
            a
= open('naz.csv','w')
            a
.write(nazv)
            a
.close()

           
self.manager.current = 'one'


понедельник, 15 февраля 2021 г., 23:52:12 UTC+3 пользователь ElliotG написал:

Elliot Garbus

unread,
Feb 16, 2021, 7:26:40 AM2/16/21
to kivy-...@googlegroups.com

Magz is a BoxLayout, not a screen, so it does not have a manager.

 

The rootwidget is the screenmanger, so Magz you can get to the ScreenManger to change the screen as:

app = App.get_running_app()

app.root.current = ‘one’

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

ТН Н

unread,
Feb 16, 2021, 9:09:49 AM2/16/21
to Kivy users support
Low bow to you.

вторник, 16 февраля 2021 г., 15:26:40 UTC+3 пользователь ElliotG написал:

ТН Н

unread,
Feb 17, 2021, 2:13:51 PM2/17/21
to Kivy users support
Dear, how can I add one specific button on viewclass that doesn't need to get a name from the list? The problem is that one such button is duplicated in the amount of how many widgets are displayed on the screen.


вторник, 16 февраля 2021 г., 15:26:40 UTC+3 пользователь ElliotG написал:

Magz is a BoxLayout, not a screen, so it does not have a manager.

Elliot Garbus

unread,
Feb 17, 2021, 4:40:12 PM2/17/21
to kivy-...@googlegroups.com

Sounds like you want one button on the screen that is not in the view class.  Put the button outside of the recycle view.

 

<MagazScreen@Screen>: 

    BoxLayout:

        orientation: ‘vertical’  

        Button:

            size_hint_y: None

            height: 48

            text: ‘One Button’      

        RV:
            viewclass: 'Magaz'
            data: self.rv_data
            RecycleGridLayout:
                cols: 2
                default_size: None, dp(200)
                default_size_hint: 1, None
                size_hint_y: None
                height: self.minimum_height

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

ТН Н

unread,
Feb 18, 2021, 5:25:52 AM2/18/21
to Kivy users support
The button is not pressed for some reason.

<Razdel>:
    BoxLayout:
        Label:
            text: root.geti
        Label:
            text: root.con_cen
        TextInput:
            on_text_validate: root.sch(self.text, self.cursor_pos)
            input_type: 'number'
            input_filter: 'float'
            multiline: False
        Button:
            text: 'Change the name
'
            on_release: root.perh(root.geti)
        Button:
            text: 'Graph for the month'
            on_release: root.graf(root.geti)
        Button:
            text: 'Graph for the year'
            on_release: root.graf_year(root.geti)
       
           
<RazdelScreen@Screen>:    
    BoxLayout:
        Button:
            text: 'Add widget +'
            size_hint_y: None
            height: 48
            #on_release: root.per(root.geti)
    RVI:
        viewclass: 'Razdel'
        data: self.rv_datas
        RecycleGridLayout:
            cols: 1

            default_size: None, dp(200)
            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height  


четверг, 18 февраля 2021 г., 0:40:12 UTC+3 пользователь ElliotG написал:

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Elliot Garbus

unread,
Feb 18, 2021, 8:45:47 AM2/18/21
to kivy-...@googlegroups.com

You want the Button and the RecycelView both under the BoxLayout.

The highlighted code below needs to be indented.  Assuming you want the button above the RecyceView, you also need to change the BoxLayout oreinetation.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/e2d9aa73-b0df-4fa3-b5a0-d1cc3936ff7bo%40googlegroups.com.

 

ТН Н

unread,
Feb 18, 2021, 9:08:00 AM2/18/21
to Kivy users support
I indented it, but it didn't help, which is strange.

четверг, 18 февраля 2021 г., 16:45:47 UTC+3 пользователь ElliotG написал:

ТН Н

unread,
Feb 19, 2021, 5:16:52 AM2/19/21
to Kivy users support
Ah no, it's work. Dear, in another topic, I asked you a question: how can I use this viewclass to instantly update the data entered by the user without restarting the program?


четверг, 18 февраля 2021 г., 16:45:47 UTC+3 пользователь ElliotG написал:

You want the Button and the RecycelView both under the BoxLayout.

Elliot Garbus

unread,
Feb 19, 2021, 7:59:33 AM2/19/21
to kivy-...@googlegroups.com

If you update the data list, the RecycleView will update.

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

ТН Н

unread,
Feb 19, 2021, 9:08:02 AM2/19/21
to Kivy users support
Is that what I'm doing wrong?

<Start>:
    GridLayout:
   
        cols: 2
       
        Button:
            text: root.name_raz
            on_release: root.per(self.text)
           
        Label:
            text: root.pot

           
    Button:
        text: 'Add widget +'
        on_release: root.per_add()
           
<StartScreen@Screen>:            
    RV:
        viewclass: 'Start'
        data: self.rv_data

        RecycleGridLayout:
            cols: 1
            default_size: None, dp(200)
            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height


<Add>:


    naz: naz
   
    BoxLayout:
        orientation: 'vertical'
        Label:
            text: 'Name'
        TextInput:
            id: naz
        Button:
            text: 'Add
'
            on_release: root.add()



class Add(Screen):
    def add(self):
        naz = self.naz.text
        a = BD()
        a.add_to_bd(naz)
        self.manager.get_screen('one').name_raz = naz
        self.manager.current = 'one'
       
class Start(BoxLayout):
    name_raz = StringProperty()
    pot = StringProperty()
    def per(self, naz):
        try:
            a = open(f'{naz}.csv')
        except FileNotFoundError:
            a = open(f'{naz}.csv', 'w')
            a.close()
        finally:
            a = Razdel
            a.get_name(1,naz)
            app = App.get_running_app()
            app.root.current = 'two'
           
    def per_add(self):
        app = App.get_running_app()
        app.root.current = 'add'

       
class RV(RecycleView):

    rv_data = ListProperty()
   
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        names = ['a','b','t']
        potra = ['c', 'd', 'e']
        self.rv_data = [{'name_raz': names[i], 'pot': str(potra[i])} for i in range(len(names))]


пятница, 19 февраля 2021 г., 15:59:33 UTC+3 пользователь ElliotG написал:

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.goo

Elliot Garbus

unread,
Feb 19, 2021, 9:23:29 AM2/19/21
to kivy-...@googlegroups.com

What is the problem.  Share an executable example.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/01fa7123-19e0-43d9-b6d0-d691477ab814o%40googlegroups.com.

 

ТН Н

unread,
Feb 19, 2021, 9:52:23 AM2/19/21
to Kivy users support
It is very difficult to send you a minimum of code, so that there is no excess and it works for you. Send you an archive with the entire project? If it's not too difficult for you to sort out my terrible writing...

пятница, 19 февраля 2021 г., 17:23:29 UTC+3 пользователь ElliotG написал:

'''

          &

Elliot Garbus

unread,
Feb 19, 2021, 9:59:44 AM2/19/21
to kivy-...@googlegroups.com

Perhaps try describing the problem, share the traceback…

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

Message has been deleted
Message has been deleted
Message has been deleted

ТН Н

unread,
Feb 19, 2021, 10:16:37 AM2/19/21
to Kivy users support
Here is a small example. It may give an error due to the fact that some files will have to be created manually or specify the path available to you. https://drive.google.com/file/d/1RQsNowP27r9N6lFB-JCumxu0urI7Eaaj/view?usp=sharing

пятница, 19 февраля 2021 г., 17:59:44 UTC+3 пользователь ElliotG написал:

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

ТН Н

unread,
Feb 19, 2021, 10:18:44 AM2/19/21
to Kivy users support
I want to immediately add widgets and display the entered numbers.

пятница, 19 февраля 2021 г., 18:16:37 UTC+3 пользователь ТН Н написал:

Elliot Garbus

unread,
Feb 19, 2021, 4:37:57 PM2/19/21
to kivy-...@googlegroups.com

To add widgets to the recycleview, add new dictionaries to the data list.

If you want to add widgets to a layout use the add_widget method.  Note you add or remove widgets from a layout.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/8a859b48-2d52-4331-8da0-20ab15e5483bo%40googlegroups.com.

 

ТН Н

unread,
Feb 20, 2021, 7:51:12 AM2/20/21
to Kivy users support
You must have misunderstood me. Widgets are already added perfectly, just to see them, you need to restart the program. And if the user enters a number in TextInput, it should be added to the number on the left in Label. But again, to see the changes, you need to restart the program.

суббота, 20 февраля 2021 г., 0:37:57 UTC+3 пользователь ElliotG написал:

'''

          &am

Elliot Garbus

unread,
Feb 20, 2021, 10:24:51 AM2/20/21
to kivy-...@googlegroups.com

Create a minimal executable example. 

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

ТН Н

unread,
Feb 20, 2021, 10:55:11 AM2/20/21
to Kivy users support
Here: https://drive.google.com/file/d/1Zf08sBUGpBm5MxB14NDbpghP0hbbf2LN/view?usp=sharing

суббота, 20 февраля 2021 г., 18:24:51 UTC+3 пользователь ElliotG написал:

'''

     &nbsp

Elliot Garbus

unread,
Feb 20, 2021, 11:09:41 AM2/20/21
to kivy-...@googlegroups.com

That is not an executable example… I can’t execute it.  Strip it down to your core question.

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

Elliot Garbus

unread,
Feb 20, 2021, 11:31:05 AM2/20/21
to kivy-...@googlegroups.com

Assuming the issue is you want to add items to your RecycleView, here is an example

 

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, ListProperty

kv =
'''
<TwoButtons>:
# This class is used as the viewclass in the RecycleView
# The means this widget will be instanced to view one element of data from the data list.
# The RecycleView data list is a list of dictionaries.  The keys in the dictionary specify the
# attributes of the widget.
    Button:
       text: root.left_text
        on_release: print(f'Button {self.text} pressed')
    Button:
        text: root.right_text
        on_release: print(f'Button {self.text} pressed')

        
BoxLayout:
    orientation: 'vertical'
    Button:
        size_hint_y: None
        height: 48
        text: 'Add widget to RV list'
        on_release: rv.add()
   
    RV:                          # A Reycleview
        id: rv
        viewclass: 'TwoButtons'  # The view class is TwoButtons, defined above.
        data: self.rv_data_list  # the data is a list of dicts defined below in the RV class.
        scroll_type: ['bars', 'content']
        bar_width: 10
        RecycleBoxLayout:       
            # This layout is used to hold the Recycle widgets
            default_size: None, dp(50)   # This sets the height of the BoxLayout that holds a TwoButtons instance.

            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height   # To scroll you need to set the layout height.
            orientation: 'vertical'
'''


class TwoButtons(BoxLayout):        # The viewclass definitions, and property definitions.
   
left_text = StringProperty()
    right_text = StringProperty()


class RV(RecycleView):
    rv_data_list = ListProperty()    
# A list property is used to hold the data for the recycleview, see the kv code

   
def __init__(self, **kwargs):
       
super().__init__(**kwargs)
       
self.rv_data_list = [{'left_text': f'Left {i}', 'right_text': f'Right {i}'} for i in range(2)]
       
# This list comprehension is used to create the data list for this simple example.
        # The data created looks like:
        # [{'left_text': 'Left 0', 'right_text': 'Right 0'}, {'left_text': 'Left 1', 'right_text': 'Right 1'},
        # {'left_text': 'Left 2', 'right_text': 'Right 2'}, {'left_text': 'Left 3'},...
        # notice the keys in the dictionary corrospond to the kivy properties in the TwoButtons class.
        # The data needs to be in this kind of list of dictionary formats.  The RecycleView instances the
        # widgets, and populates them with data from this list.

   
def add(self):
        l =
len(self.rv_data_list)
       
self.rv_data_list.extend([{'left_text': f'Added Left {i}', 'right_text': f'Added Right {i}'} for i in range(l,l+1)])



class RVTwoApp(App):
   
def build(self):
       
return Builder.load_string(kv)


RVTwoApp().run()
Message has been deleted
Message has been deleted

ТН Н

unread,
Feb 20, 2021, 1:04:38 PM2/20/21
to Kivy users support
Where did I go wrong?

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.widget import Widget
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout

from kivy.uix.recycleview import RecycleView
from kivy.properties import StringProperty, ListProperty
from kivy.uix.screenmanager import Screen, ScreenManager, NoTransition
import csv


kv
= '''
ScreenManager:
    StartScreen:
        name: '
one'
    Add_tov:
        name: '
add'

           
<Start>:
    GridLayout:
   
        cols: 2
       
        Button:
            text: root.name_raz
            on_release: print('Touch')
           
<StartScreen@Screen>:  
    BoxLayout:
       
        orientation: '
vertical'
       
        RV:
            id: rv
            viewclass: '
Start'
            data: self.rv_data
            scroll_type: ['
bars', 'content']
            bar_width: 10

            RecycleGridLayout:
                cols: 1
                default_size: None, dp(200)
                default_size_hint: 1, None
                size_hint_y: None
                height: self.minimum_height
               
        Button:
            text: '
Add +'
            size_hint_y: None
            height: 48
            on_release: root.per()


<Add_tov>:


    naz: naz
   
    BoxLayout:
   
        orientation: '
vertical'
       
        Label:
            text: '
Name'

        TextInput:
            id: naz
        Button:
            text: '
Add'
            on_release: root.add()  
        Button:
            text: '
Back'
            on_release: root.manager.current = '
one'
           
'''



class StartScreen(Screen):
   
def per(self):
        a
= App.get_running_app()
        a
.root.current = 'add'


class Start(Screen):

    name_raz
= StringProperty()
    pot
= StringProperty()
   
class RV(RecycleView):


    rv_data
= ListProperty()
   
   
def __init__(self, **kwargs):
       
super().__init__(**kwargs)

       
try:
            a
= open('names.csv')
       
except FileNotFoundError:
            a
= open('names.csv', 'w')
            a
.write('Wid 1, Wid 2, Wid 3')
            a
.close()
            a
= open('names.csv')
        b
= csv.reader(a)
        c
= next(b)
       
self.d = []
       
for i in c:
           
self.d.append(i)
       
self.rv_data = [{'name_raz': self.d[i]} for i in range(len(self.d))]
       
   
def add(self):
       
self.rv_data.extend([{'name_raz': self.d[i]} for i in range(len(self.d))])
        a
= App.get_running_app()
        a
.root.current = 'one'
   
class Add_tov(Screen):
   
def add(self):
        nam
= self.naz.text
        a
= open('names.csv', 'a')
        a
.write(','+nam)
        a
.close()
        a
= RV()
        a
.add()      
       
class TestApp(App):
   
def build(self):
       
return Builder.load_string(kv)  


TestApp().run()

    

суббота, 20 февраля 2021 г., 19:31:05 UTC+3 пользователь ElliotG написал:


            nazv
= naz.<span style='font-size:10.0pt;font-fami

Elliot Garbus

unread,
Feb 20, 2021, 2:05:56 PM2/20/21
to kivy-...@googlegroups.com

 

It is more ‘pythonic’ to use:

[{'name_raz': v} for v in self.d)] rather than: [{'name_raz': self.d[i]} for i in range(len(self.d))]

 

Start should not be a screen.  It should be a BoxLayout.

You also have a problem with add in Add_tov(). 

 

class Start(Screen):  # Make a BoxLayout or other Layout


    name_raz
= StringProperty()
    pot
= StringProperty()

class Add_tov(Screen):
   
def add(self):
        nam
= self.naz.text
        a
= open('names.csv', 'a')
        a
.write(','+nam)
        a
.close()


        # a
= RV()  # what are you trying to do here?
        # a.add()  

        self.manager.get_screen('one').ids.rv.add()  # you need to access the existing instance, not create a new one 

    

 

From: ТН Н
Sent: Saturday, February 20, 2021 11:05 AM
To: Kivy users support
Subject: Re: [kivy-users] How in can gridlayout limit the numberofrowsforwidgetstotwo,iftherecanbemanymorewidgets?

 

Where did I go wrong?

 


        a
= RV()  # what are you trying to do here?

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

ТН Н

unread,
Feb 20, 2021, 2:30:31 PM2/20/21
to Kivy users support
Does it work for you? When you use Boxlayout instead of the Screen I get this error message: ScreenManager accepts only Screen widget. And if you return the Screen, the new widget is not added immediately.

суббота, 20 февраля 2021 г., 22:05:56 UTC+3 пользователь ElliotG написал:


            on_release: root.add()  
        Button:
            text: '
Back<span style='f

Elliot Garbus

unread,
Feb 20, 2021, 2:45:26 PM2/20/21
to kivy-...@googlegroups.com

I am not running your code. 

You have a Screen StartScreen and a viewclass Start.  You are getting these confused. 

You may want a more descriptive name for your viewclass.

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

ТН Н

unread,
Feb 20, 2021, 5:21:40 PM2/20/21
to Kivy users support
Oh, sorry, I got the classes mixed up. Everything works, only very strangely... Instead of adding a new widget, copies of the existing ones are created. But after restarting the program, the widgets are displayed as they should.

суббота, 20 февраля 2021 г., 22:45:26 UTC+3 пользователь ElliotG написал:

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

ТН Н

unread,
Feb 21, 2021, 6:20:42 AM2/21/21
to Kivy users support
Using the print command, I realized that the list remains unchanged. So I filled it in again and added the last element. It works. Thank you, dear.


суббота, 20 февраля 2021 г., 22:45:26 UTC+3 пользователь ElliotG написал:

I am not running your code. 

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

ТН Н

unread,
Feb 21, 2021, 1:42:19 PM2/21/21
to Kivy users support
Dear, can you explain in more detail what the extend method does? Or give a link to the documentation, something I can't find about this method. That's what I'm interested in: does it completely update the list or supplement it? If it complements, then how do I make it do it on the index I specified. I just have problems with two things in the code, the widgets are not updated there, I'm trying to solve it.


суббота, 20 февраля 2021 г., 22:45:26 UTC+3 пользователь ElliotG написал:

I am not running your code. 

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Elliot Garbus

unread,
Feb 21, 2021, 1:49:43 PM2/21/21
to kivy-...@googlegroups.com

From the Python.org docs:

https://docs.python.org/3/tutorial/datastructures.html#more-on-lists

https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types

 

extend adds the items in a list to the end of another list.

 

To add content to a specific index, see the list method insert.  The insert method is also in the docs above.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6fc5d47c-2ac8-42c4-88e9-203e0fbb9826o%40googlegroups.com.

 

ТН Н

unread,
Feb 21, 2021, 4:24:38 PM2/21/21
to Kivy users support
I knew how to replace an element by index, but I don't understand how to do it in this entry: self.rv_datas.extend([{'geti': e[-1], 'con_cen': dd[-1]} for i in range(1)])
Here is a difficult situation, I need to keep" geti "as it is, and in" con-cen " replace the specific element self.rv_datas with dd[-1].

воскресенье, 21 февраля 2021 г., 21:49:43 UTC+3 пользователь ElliotG написал:

Elliot Garbus

unread,
Feb 21, 2021, 6:48:00 PM2/21/21
to kivy-...@googlegroups.com

See the code below.  Fool with code like this in IDLE or at an interactive prompt to learn how these pieces fit together.

 

>>> list_of_dicts = [{'a': i, 'b': i + 1} for i in range(0, 8, 2)]   # a list comprehension creates the elements in the list, each element is a dictionary.

>>> list_of_dicts

[{'a': 0, 'b': 1}, {'a': 2, 'b': 3}, {'a': 4, 'b': 5}, {'a': 6, 'b': 7}]    # The list that the list comprehension created

>>> list_of_dicts[2]         # access element 2 of the list

{'a': 4, 'b': 5}

>>> list_of_dicts[2]['a']    # get element [2][‘a’]

4

>>> list_of_dicts[2]['a'] = 'What ?'    # Set element [2][‘a’]

>>> list_of_dicts[2]

{'a': 'What ?', 'b': 5}

>>> list_of_dicts[2]['b'] = 'Hello world'   # Set element [2][‘b’]

>>> list_of_dicts

[{'a': 0, 'b': 1}, {'a': 2, 'b': 3}, {'a': 'What ?', 'b': 'Hello world'}, {'a': 6, 'b': 7}]  # The list with element [2] updated

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/623fa0de-ec1d-471a-b32b-10f11b561537o%40googlegroups.com.

 

ТН Н

unread,
Feb 22, 2021, 4:49:19 AM2/22/21
to Kivy users support
I understood. Thanks.

понедельник, 22 февраля 2021 г., 2:48:00 UTC+3 пользователь ElliotG написал:

ТН Н

unread,
Feb 22, 2021, 8:43:43 AM2/22/21
to Kivy users support
I can't guess how in the entry above to clear the list with the remove() method.


понедельник, 22 февраля 2021 г., 2:48:00 UTC+3 пользователь ElliotG написал:

See the code below.  Fool with code like this in IDLE or at an interactive prompt to learn how these pieces fit together.

Elliot Garbus

unread,
Feb 22, 2021, 9:56:31 AM2/22/21
to kivy-...@googlegroups.com

I’m not sure I understand your question, if you want to clear a list you can use the clear method.

 

>>> list_of_dicts = [{'a': i, 'b': i + 1} for i in range(0, 8, 2)]

>>> list_of_dicts

[{'a': 0, 'b': 1}, {'a': 2, 'b': 3}, {'a': 4, 'b': 5}, {'a': 6, 'b': 7}]

>>> list_of_dicts.clear()

>>> list_of_dicts

[]

 

If you want to remove one or more item from the list you can delete it with an index or slice notation

>>> list_of_dicts = [{'a': i, 'b': i + 1} for i in range(0, 8, 2)]

>>> list_of_dicts

[{'a': 0, 'b': 1}, {'a': 2, 'b': 3}, {'a': 4, 'b': 5}, {'a': 6, 'b': 7}]

>>> del list_of_dicts[-1]

>>> list_of_dicts

[{'a': 0, 'b': 1}, {'a': 2, 'b': 3}, {'a': 4, 'b': 5}]

>>> del list_of_dicts[1:]

>>> list_of_dicts

[{'a': 0, 'b': 1}]

 

To use the remove method, the element you want to remove must be equal to an item on the list:

>>> list_of_dicts = [{'a': i, 'b': i + 1} for i in range(0, 8, 2)]

>>> list_of_dicts

[{'a': 0, 'b': 1}, {'a': 2, 'b': 3}, {'a': 4, 'b': 5}, {'a': 6, 'b': 7}]

>>> r = {'a': 2, 'b': 3}

>>> list_of_dicts.remove(r)

>>> list_of_dicts

[{'a': 0, 'b': 1}, {'a': 4, 'b': 5}, {'a': 6, 'b': 7}]

>>> list_of_dicts.remove({'a': 4, 'b': 5})

>>> list_of_dicts

[{'a': 0, 'b': 1}, {'a': 6, 'b': 7}]

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/4c573b30-e4b9-40b1-abb4-0a9d9617c734o%40googlegroups.com.

 

ТН Н

unread,
Feb 25, 2021, 3:39:55 PM2/25/21
to Kivy users support
Dear, I tried using list cleanup to solve the problem, but it didn't give the desired result. The problem is this: in my program, when you click on different buttons, you should go to a screen with a different set of widgets, but this does not happen. The set of widgets is always the same, the one that was created when the program was launched. To see the desired result, you need to restart the program. I know, I don't know how to explain, so I wrote a code that roughly shows how it works.

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.widget import Widget
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.recycleview import RecycleView
from kivy.properties import StringProperty, ListProperty
from kivy.uix.screenmanager import Screen, ScreenManager, NoTransition
import csv


kv
= '''
ScreenManager:
    StartScreen:
        name: '
one
'
    SeeScreen:
        name: '
see'

           
<Start>:
    GridLayout:
   
        cols: 2
       
        Button:
            text: root.name_raza
            on_release: root.per()
           
<StartScreen@Screen>:  
    BoxLayout:
       
        orientation: '
vertical'
       
        RV:
            id: rv
            viewclass: '
Start'
            data: self.rv_datas

            RecycleGridLayout:
                cols: 1
                default_size: None, dp(200)
                default_size_hint: 1, None
                size_hint_y: None
                height: self.minimum_height


<See>:
   
    BoxLayout:
   
        orientation: '
vertical'
       
        Label:
            text: root.names
           
<SeeScreen@Screen>:  
    BoxLayout:
       
        orientation: '
vertical'
       
        RVI:
            id: rvi
            viewclass: '
See'
            data: self.rv_data

            RecycleGridLayout:
                cols: 1
                default_size: None, dp(200)
                default_size_hint: 1, None
                size_hint_y: None
                height: self.minimum_height
               
        Button:
            text: 'Back'
            size_hint_y: None
            height: 48
            on_release: root.manager.current = '
one'
           
'''

a
= open('number.csv')
b
= a.read()
btn
= int(b)


class Start(BoxLayout):
    name_raza
= StringProperty()
   
   
def per(self):
        a
= RVI()
        a
= App.get_running_app()
        a
.root.current = 'see'
   
class RV(RecycleView):


    rv_datas
= ListProperty()
   
   
def __init__(self, **kwargs):
       
super().__init__(**kwargs)
        d
= ['One', 'Two', 'Three']
       
self.rv_datas = [{'name_raza': i} for i in d]
       
print(d)
   
class See(BoxLayout):
    names
= StringProperty()


class RVI(RecycleView):

    rv_data
= ListProperty()
   
   
def __init__(self, **kwargs):
       
super().__init__(**kwargs)

       
global btn
       
try:
            a
= open(f'Namess{btn}.csv')
       
except FileNotFoundError:          
            a
= open(f'Namess{btn}.csv', 'w')
            a
.write(f'Wid {btn}, Wid {btn}, Wid {btn}')
            a
.close()
            a
= open(f'Namess{btn}.csv')
            btn
+= 1
            wr
= open('number.csv', 'w')
            wr
.write(str(btn))

        b
= csv.reader(a)
        c
= next(b)

        d
= []
       
for i in c:

            d
.append(i)
       
self.rv_data = [{'names': i} for i in d]
       
print(d)

       
class TestApp(App):
   
def build(self):
       
return Builder.load_string(kv)  


TestApp().run()

    

понедельник, 22 февраля 2021 г., 17:56:31 UTC+3 пользователь ElliotG написал:

Elliot Garbus

unread,
Feb 25, 2021, 4:33:37 PM2/25/21
to kivy-...@googlegroups.com

The attached program has 2 screens: ‘one’ and ‘see’

Pressing any button on ‘one’ changes the screen to ‘see’

See shows 3 labels, and has a back button.

 

At program initialization, the code reads 'number.csv'.  This is used to select a different file, that is opened and the values in the second file go on the labels on ‘see’.

There is no action, button or event that can change the state of the program.

 

I don’t have a clue what you are trying to do.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/037f7457-b0a7-42a6-9034-7a44868e3365o%40googlegroups.com.

 

ТН Н

unread,
Feb 26, 2021, 7:29:50 AM2/26/21
to Kivy users support
The number.csv should initially store the number 1. When you click on the button, a screen with 'Wid 1'(x3) opens, when you click on another or the same button, there should be a screen with 'Wid 2'(x3), but to do this, you need to restart the program. How do I make an action or event so that it happens without restarting?

пятница, 26 февраля 2021 г., 0:33:37 UTC+3 пользователь ElliotG написал:


  &n

Elliot Garbus

unread,
Feb 26, 2021, 9:25:03 AM2/26/21
to kivy-...@googlegroups.com

A number of changes have been made below.  The key issue with your previous code. You were updating the rv_data in __init__() this only runs when the object is created.  You were creating an RVI object in per() that was never connected to the widget tree, but the __init__() would run – showing you changes in the print statement.

 

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.recycleview import RecycleView
from kivy.properties import StringProperty, ListProperty, NumericProperty
# a = open('number.csv')  # I moved these globals to app and on_start
# b = a.read()
# btn = int(b)



class Start(BoxLayout):
    name_raza = StringProperty()

   
def per(self
):
       
# a = RVI()
       
app = App.get_running_app()
        app.root.get_screen(
'see').ids.rvi.update()  # call the update method
       
app.root.current = 'see'


class RV(RecycleView):
    rv_datas = ListProperty()

   
def __init__(self, **kwargs):
       
super().__init__(**kwargs)
        d = [
'One', 'Two', 'Three']
       
self.rv_datas = [{'name_raza': i} for i in d]
       
print(d)


class See(BoxLayout):
    names = StringProperty()


class RVI
(RecycleView):
    rv_data = ListProperty()

   
def __init__(self, **kwargs):
       
super().__init__(**kwargs)
       
self.update()                    # moved code to update

   
def update(self):                    # Created new method update
       
app = App.get_running_app()
        btn = app.btn
       
# global btn
       
try:
            a =
open(f'Namess{btn}.csv')
       
except FileNotFoundError:
            a =
open(f'Namess{btn}.csv', 'w')
            a.write(
f'Wid {btn}, Wid {btn}, Wid {btn}')
            a.close()
            a =
open(f'Namess{btn}.csv')
           
# btn += 1
           
wr = open('number.csv', 'w')
            wr.write(
str(btn))


        b = csv.reader(a)
        c =
next(b)

        d = []
       
for i in c:
            d.append(i)
       
self.rv_data = [{'names': i} for i in d]
       
print(d)
        app.btn +=
1


class TestApp(App):
    btn = NumericProperty()

   
def build(self):
       
with open('number.csv') as a:    #  You need to add the exception if the file does not exist..
           
self.btn = int(a.read())
       
return Builder.load_string(kv)


TestApp().run()

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

ТН Н

unread,
Feb 26, 2021, 11:15:40 AM2/26/21
to Kivy users support
It works! I am very grateful to you.

пятница, 26 февраля 2021 г., 17:25:03 UTC+3 пользователь ElliotG написал:


        d
= ['One',<span style='font-size:10.0pt;font-family:"Courier New";color:blac

Reply all
Reply to author
Forward
0 new messages