<NScreen>: MDCard: orientation: "vertical" padding: "8dp" size_hint: None, None size: "280dp", "180dp" pos_hint: {"center_x": .5, "center_y": .5}
MDLabel: text: "Title" theme_text_color: "Secondary" size_hint_y: None height: self.texture_size[1]
MDSeparator: height: "1dp"
MDLabel: text: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book"
class NScreen(Screen):
def on_start(self): self.ids.box.add_widget( MDLabel( text="{name_style} style", halign="center", ))
It is much easier when you ask question if you provide a minimal runnable example.
Looking are your code
In your python code add an appropriate property for each data type you want to display ie:
class NScreen(Screen):
title = StringProperty()
text_content = StringProperty()
in your kv code have the kv code use these properties
<NScreen>:
MDCard:
orientation: "vertical"
padding: "8dp"
size_hint: None, None
size: "280dp", "180dp"
pos_hint: {"center_x": .5, "center_y": .5}
MDLabel:
text: "root.text"
theme_text_color: "Secondary"
size_hint_y: None
height: self.texture_size[1]
MDSeparator:
height: "1dp"
MDLabel:
text: "text_content"
In your python code set the properties, for example:
class NScreen(Screen):
title = StringProperty()
text_content = StringProperty()
def set_title(self, t)
self.title = t
If you are instancing the NScreen instances in python you can use keyword arguments:
card_screen = NScreen(text=’This is the title’, text_content=’This is the content’)
--
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/c8822920-2cae-4ecc-a5b3-67b3d88823aco%40googlegroups.com.
<NScreen>:
MDCard: orientation: "vertical" padding: "8dp" size_hint: None, None size: "280dp", "180dp" pos_hint: {"center_x": .5, "center_y": .5} MDLabel: text: "root.text" theme_text_color: "Secondary" size_hint_y: None height: self.texture_size[1] MDSeparator: height: "1dp" MDLabel: text: "text_content"
class NScreen(Screen):
title = StringProperty() text_content = StringProperty()
def set_title(self, t): con = sqlite3.connect('test.db') cur = con.cursor() cur.execute("SELECT * FROM news ORDER BY id ASC") table = cur.fetchall()
for line in table: title, news_content = line card_screen = NScreen(text=title, text_content=news_content) self.title = card_screen
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.
Issues highlighted below
Do you have a place to call set_title or do you need this called by an event?
Please post a minimal runnable example.
<NScreen>:
MDCard:
orientation: "vertical"
padding: "8dp"
size_hint: None, None
size: "280dp", "180dp"
pos_hint: {"center_x": .5, "center_y": .5}
MDLabel:
text: root.text # not "root.text"
theme_text_color: "Secondary"
size_hint_y: None
height: self.texture_size[1]
MDSeparator:
height: "1dp"
MDLabel:
text: root.text_content # "text_content"
class NScreen(Screen):
title = StringProperty()
text_content = StringProperty()
def set_title(self): # you are not using t (self, t):
con = sqlite3.connect('test.db')
cur = con.cursor()
cur.execute("SELECT * FROM news ORDER BY id ASC")
table = cur.fetchall()
for line in table:
title, news_content = line
# card_screen = NScreen(text=title, text_content=news_content) # do not instance the class inside the class
self.title = title # card_screen
self.text_content = news_content
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/caa2f84f-5baf-4201-a3d0-3a61c26f8a6ao%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/caa2f84f-5baf-4201-a3d0-3a61c26f8a6ao%40googlegroups.com.
Post a minimal runnable example. You could also replace the database with a list to see if the issue is the database or the display of the data.
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/73b9cc6a-a9b3-4ab9-996b-d0d0ea347cfbo%40googlegroups.com.
<NScreen>:
MDCard: orientation: "vertical" padding: "8dp" size_hint: None, None size: "280dp", "180dp" pos_hint: {"center_x": .5, "center_y": .5} MDLabel:
text: root.title
theme_text_color: "Secondary" size_hint_y: None height: self.texture_size[1] MDSeparator: height: "1dp" MDLabel: text: root.text_content
theme_text_color: "Secondary"
class NScreen(Screen):
title = StringProperty() text_content = StringProperty()
def set_title(self):
con = sqlite3.connect('test.db') cur = con.cursor() cur.execute("SELECT * FROM news ORDER BY id ASC") table = cur.fetchall()
for line in table: title, news_content = line
self.title = title self.text_content = news_content
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/73b9cc6a-a9b3-4ab9-996b-d0d0ea347cfbo%40googlegroups.com.
When I say a minimal runnable example, I mean code I can 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/bc22ffd8-b355-4416-bc5e-d9e5b0b2d1ffo%40googlegroups.com.
from kivy.lang import Builderfrom kivy.uix.screenmanager import ScreenManager, Screenimport sqlite3from kivymd.app import MDAppfrom kivy.properties import ListProperty, StringPropertyfrom kivy.uix.boxlayout import BoxLayoutfrom kivymd.uix.label import MDLabel
kv = '''
BoxLayout: orientation: 'vertical' MDToolbar: id: toolbar elevation: 10 title: "Sports App" left_action_items: [["menu", lambda x: nav_drawer.set_state("open")]]
MDNavigationLayout: ScreenManager: id: screen_manager HomeScreen: id: home name: 'home' NScreen: id: news name: 'news' MDNavigationDrawer: id: nav_drawer ScrollView: MDList: OneLineListItem: icon: 'soccer' text: "Home" on_press: nav_drawer.set_state("close") screen_manager.current = "home" OneLineListItem: text: "News" on_press: nav_drawer.set_state("close") screen_manager.current = "news"
<HomeScreen>: MDLabel: text: 'Home screen' halign: 'center'
<NScreen>:
MDCard: orientation: "vertical" padding: "8dp" size_hint: None, None size: "280dp", "180dp" pos_hint: {"center_x": .5, "center_y": .5} MDLabel: text: root.title theme_text_color: "Secondary" size_hint_y: None height: self.texture_size[1] MDSeparator: height: "1dp" MDLabel: text: root.text_content theme_text_color: "Secondary"'''
class HomeScreen(Screen): pass
class NScreen(Screen):
title = StringProperty() text_content = StringProperty()
def set_title(self): con = sqlite3.connect('test.db') cur = con.cursor() cur.execute("SELECT * FROM news ORDER BY id ASC") table = cur.fetchall()
for line in table: title, news_content = line
self.title = title # card_screen self.text_content = news_content
class ScrManage(ScreenManager): pass
class Sports(MDApp): def build(self): return Builder.load_string(kv)
Sports().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/bc22ffd8-b355-4416-bc5e-d9e5b0b2d1ffo%40googlegroups.com.
Nothing was calling your code… Give this a try – then change back to using your database.
'''
on_pre_enter: self.set_title()
MDCard:
orientation: "vertical"
padding: "8dp"
size_hint: None, None
size: "280dp", "180dp"
pos_hint: {"center_x": .5, "center_y": .5}
MDLabel:
text: root.title
theme_text_color: "Secondary"
size_hint_y: None
height: self.texture_size[1]
MDSeparator:
height: "1dp"
MDLabel:
text: root.text_content
theme_text_color: "Secondary"
'''
class HomeScreen(Screen):
pass
class NScreen(Screen):
title = StringProperty()
text_content = StringProperty()
def set_title(self
):
# con = sqlite3.connect('test.db')
# cur = con.cursor()
# cur.execute("SELECT * FROM news ORDER BY id ASC")
# table = cur.fetchall()
table = [['And Now This...', 'The News goes here! A series of fascinating facts!']]
for line in table:
title, news_content = line
self.title = title # card_screen
self.text_content = news_content
class ScrManage(ScreenManager):
pass
class Sports(MDApp):
def build(self):
return Builder.load_string(kv)
Sports().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/29e17e3c-2fc8-45b4-bcf6-498ac45f01b3o%40googlegroups.com.
<NScreen>: on_pre_enter: self.set_title() MDCard: orientation: "vertical" padding: "8dp" size_hint: None, None size: "280dp", "180dp"
pos_hint: {"top": .95, "left": .9}
MDLabel: text: root.title theme_text_color: "Secondary" size_hint_y: None height: self.texture_size[1] MDSeparator: height: "1dp" MDLabel: text: root.text_content theme_text_color: "Secondary"
class NScreen(Screen):
title = StringProperty() text_content = StringProperty()
def set_title(self): con = sqlite3.connect('test.db') cur = con.cursor()
cur.execute("SELECT * FROM news")
table = cur.fetchall() for line in table:
id, title, content = line self.title = title self.text_content = content
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/29e17e3c-2fc8-45b4-bcf6-498ac45f01b3o%40googlegroups.com.
If you want multiple cards in a list, you will need to create a ScrollView, use a layout to hold multiple cards, and instance a new card for each line in the database response.
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/b2252e3b-49a2-4d88-affd-bd68a4ccc621o%40googlegroups.com.
<NScreen>: on_pre_enter: self.set_title() ScrollView:
MDCard: orientation: "vertical" padding: "8dp" size_hint: None, None size: "280dp", "180dp" pos_hint: {"top": .95, "left": .9} MDLabel: text: root.title theme_text_color: "Secondary" size_hint_y: None height: self.texture_size[1] MDSeparator: height: "1dp" MDLabel: text: root.text_content theme_text_color: "Secondary"
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/b2252e3b-49a2-4d88-affd-bd68a4ccc621o%40googlegroups.com.
On Jan 27, 2021, at 8:21 AM, kivy <testo...@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/d3784141-0845-4f97-8de0-5dfc45dcba18o%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/d3784141-0845-4f97-8de0-5dfc45dcba18o%40googlegroups.com.
Here you go:
Key changes:
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
import sqlite3
from kivymd.app import MDApp
from kivymd.uix.card import MDCard
'''
<InfoCard>: # put the MD Card in a seperate class
orientation: "vertical"
padding: "8dp"
size_hint: None, None
size: "280dp", "180dp"
pos_hint: {"center_x": .5, "center_y": .5}
MDLabel:
text: root.title
theme_text_color: "Secondary"
size_hint_y: None
height: self.texture_size[1]
MDSeparator:
height: "1dp"
MDLabel:
text: root.text_content
theme_text_color: "Secondary"
<NScreen>:
on_pre_enter: self.set_title()
ScrollView:
do_scroll_x: True
do_scroll_y: False
scroll_type: ['bars', 'content']
bar_width: '10dp'
BoxLayout:
padding: '20dp'
spacing: '20dp'
id: card_box
width: self.minimum_width
size_hint_x: None
# MDCard:
# orientation: "vertical"
# padding: "8dp"
# size_hint: None, None
# size: "280dp", "180dp"
# pos_hint: {"center_x": .5, "center_y": .5}
#
# MDLabel:
# text: root.title
# theme_text_color: "Secondary"
# size_hint_y: None
# height: self.texture_size[1]
#
# MDSeparator:
# height: "1dp"
#
# MDLabel:
# text: root.text_content
# theme_text_color: "Secondary"
'''
class HomeScreen(Screen):
pass
class InfoCard(MDCard):
title = StringProperty()
text_content = StringProperty()
class NScreen(Screen):
def set_title(self):
# con = sqlite3.connect('test.db')
# cur = con.cursor()
# cur.execute("SELECT * FROM news ORDER BY id ASC")
# table = cur.fetchall()
table = [['And Now This...0', 'The News goes here! A series of fascinating facts!'],
['And Now This...1', 'The News goes here! A series of fascinating facts!'],
['And Now This...2', 'The News goes here! A series of fascinating facts!'],
['And Now This...3', 'The News goes here! A series of fascinating facts!'],
['And Now This...4', 'The News goes here! A series of fascinating facts!'],
]
for line in table:
title, news_content = line
self.ids.card_box.add_widget(InfoCard(title=title, text_content=news_content))
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/c7d4fee0-9405-45a9-a80f-28de7a56f1fdo%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/c7d4fee0-9405-45a9-a80f-28de7a56f1fdo%40googlegroups.com.
😊
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/1729281f-cd32-451b-867d-75ca9a23cb31o%40googlegroups.com.