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.
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()
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.
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/3eee5759-6f59-4798-b72f-97f2ee855e9do%40googlegroups.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.
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/b390c432-d737-4bc1-803a-3201736ae5e1o%40googlegroups.com.
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()
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()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/b390c432-d737-4bc1-803a-3201736ae5e1o%40googlegroups.com.
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.
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/880BCF4B-43B7-495E-B990-F6E2075CB9A0%40cox.net.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/2fa1a708-77ec-4ab3-b874-9857dba35dd8o%40googlegroups.com.
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/880BCF4B-43B7-495E-B990-F6E2075CB9A0%40cox.net.
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()
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/2fa1a708-77ec-4ab3-b874-9857dba35dd8o%40googlegroups.com.
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/880BCF4B-43B7-495E-B990-F6E2075CB9A0%40cox.net.
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/a1f7270c-9d55-4cc3-af1b-dcc4dae1f3ado%40googlegroups.com.
You data list has an issue:
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/a1f7270c-9d55-4cc3-af1b-dcc4dae1f3ado%40googlegroups.com.
You data list has an issue:
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/a1f7270c-9d55-4cc3-af1b-dcc4dae1f3ado%40googlegroups.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.
#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()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/237d5ee4-c524-43ac-9d6f-3380cccb65f5o%40googlegroups.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 написал:
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/237d5ee4-c524-43ac-9d6f-3380cccb65f5o%40googlegroups.com.
--
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/bc0d3ed4-7a50-469c-87f7-b2e1589ddcd7o%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/bc0d3ed4-7a50-469c-87f7-b2e1589ddcd7o%40googlegroups.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:
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/bc0d3ed4-7a50-469c-87f7-b2e1589ddcd7o%40googlegroups.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:
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/bc0d3ed4-7a50-469c-87f7-b2e1589ddcd7o%40googlegroups.com.
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()
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:
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/bc0d3ed4-7a50-469c-87f7-b2e1589ddcd7o%40googlegroups.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.
class TwoButtons(BoxLayout):
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/e17a8367-eaf9-44a0-91d1-1b38c78b6c87o%40googlegroups.com.
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()
To unsubscribe from this group and stop receiving emails from it, send an email 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.
User Builder.load_string(kv), as in the example I shared.
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/44a881b9-b9d4-4ed7-9ccd-25105cdf090fo%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.
In KV
To unsubscribe from this group and stop receiving emails from it, send an email 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.
.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()
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
In KV
To unsubscribe from this group and stop receiving emails from it, send an email 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.
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'
pos_hint:{'center_x': .5, 'y': .4}</spa
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/e84f5d95-a242-4bc7-9f6f-f251645528f4o%40googlegroups.com.
ScreenManager:
Start:
name: 'one'
Add:
name: 'add'
See_tov:
name: 'see'
price: price<spa
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/7436daed-4e5d-466d-9cf3-39dd205d70a0o%40googlegroups.com.
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
pos_hint:{'center_x': .5, 'y': .2}<span style='font-size:10.0pt;font-
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/bf45659c-9d92-4131-9509-06ab4ec7e044o%40googlegroups.com.
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()
<span sty
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/d6f99c2f-16ef-488e-9313-7b49c7a64ccdo%40googlegroups.com.
Not new...
<span class=s
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()
Not new...
<span class=s
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/7a071540-03b4-4b80-bd5c-1b8e0f9ba0e4o%40googlegroups.com.
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'
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/3fcc48ca-4ffd-4ea5-b74a-dbffd2de1d34o%40googlegroups.com.
Magz is a BoxLayout, not a screen, so it does not have a manager.
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/48638e81-f94d-4b14-9928-d86fc5d9e773o%40googlegroups.com.
<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
To unsubscribe from this group and stop receiving emails from it, send an email 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.
You want the Button and the RecycelView both under the BoxLayout.
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/c757066c-f096-436e-b09d-89cdab58ca8eo%40googlegroups.com.
<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))]
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
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.
'''
&
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/9b1b4969-6554-4eb0-b5bd-9a0026674ad0o%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email 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.
'''
&am
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/1d5b8135-5308-4a0c-aa74-a38711095df2o%40googlegroups.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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6405d481-9e7d-48a4-b98e-dfe117779111o%40googlegroups.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()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6031343f.1c69fb81.1c52e.db5eSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
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()
nazv = naz.<span style='font-size:10.0pt;font-fami
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/1f3872fd-5378-44b1-915f-1f9796771b70o%40googlegroups.com.
on_release: root.add()
Button:
text: 'Back<span style='f
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6152a3bf-ab4e-4f3a-8eca-24c34a6b6d68o%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.
I am not running your code.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.
I am not running your code.
To unsubscribe from this group and stop receiving emails from it, send an email 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6fc5d47c-2ac8-42c4-88e9-203e0fbb9826o%40googlegroups.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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/623fa0de-ec1d-471a-b32b-10f11b561537o%40googlegroups.com.
See the code below. Fool with code like this in IDLE or at an interactive prompt to learn how these pieces fit together.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/623fa0de-ec1d-471a-b32b-10f11b561537o%40googlegroups.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.
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()
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.
&n
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/d9c452bc-1b7c-487d-b9ee-768e5020da57o%40googlegroups.com.
d = ['One',<span style='font-size:10.0pt;font-family:"Courier New";color:blac