I want to add text using OneLineListItem from the python module kivymd. When I run my code I only get the scrollview and no text inside the screen. I'm not sure what I'm doing wrong. I would like to get any ideas from anyone. I posted the code here below feel free to look at the code. Hello people I need a solution to my issue. Thanks!!
from kivymd.app import MDApp
from kivy.core.window import Window
from kivymd.uix.list import ThreeLineAvatarListItem, ImageLeftWidget
Window.size = (360, 500)
class DemoApp(MDApp):
def build(self):
self.theme_cls.primary_palette = "Yellow"
self.theme_cls.primary_hue = 'A400'
self.theme_cls.theme_style = 'Dark'
pass
def on_start(self):
for i in range(10):
image = ImageLeftWidget(source="soldier.jpg")
items = ThreeLineAvatarListItem(text="Item " + str(i), secondary_text="Hello World", tertiary_text="Third text")
items.add_widget(image)
self.root.ids.container.add_widget(items)
#:include firebaseloginscreen.kv
#:import FirebaseLoginScreen firebaseloginscreen.FirebaseLoginScreen
#:import utils kivy.utils
#: import FadeTransition kivy.uix.screenmanager.FadeTransition
#: import SlideTransition kivy.uix.screenmanager.SlideTransition
#FloatLayout:
ScreenManager:
id: screen_manager
canvas.before:
Color:
rgb: 1,1,1
Rectangle:
size: self.size
pos: self.pos
FirebaseLoginScreen:
canvas.before:
Rectangle:
size: self.size
pos: self.pos
source: "heart.png"
id: firebase_login_screen
name: "firebase_login_screen"
size_hint: 1,1
pos_hint: {"top": 1, "right": 1}
web_api_key: "AIaSyCqafRzds38uZDLlKuI"
primary_color: utils.get_color_from_hex("#e6e600")#("#EE682A")
secondary_color: utils.get_color_from_hex("#060809")
tertiary_color: utils.get_color_from_hex("#434343")
on_login_success:
app.user_localId = self.localId
app.user_idToken = self.idToken
screen_manager.transition = FadeTransition(duration=0.01)
screen_manager.current = "main_app_screen"
#screen_manager.transition.direction = 'right'
print(firebase_login_screen.refresh_token_file)
Screen:
name: "main_app_screen"
NavigationLayout:
ScreenManager:
Screen:
name: "main_app_screen"
canvas.before:
Rectangle:
size: self.size
pos: self.pos
source: "3cr_2.png"
BoxLayout:
orientation: 'vertical'
spacing: '0.5dp'
MDToolbar:
title: "Tools"
left_action_items: [["menu", lambda x: nav_drawer.toggle_nav_drawer()]]
MDIconButton:
icon: 'message'
on_press: screen_manager.current = "messages"
theme_text_color: 'Custom'
md_bg_color: app.theme_cls.primary_color
MDBottomAppBar:
MDToolbar:
title: 'Calendar'
left_action_items: [['calendar', lambda x: app.calendar()]]
mode: 'free-end'
icon: 'sword'
on_action_button: app.navigation_draw()
Widget:
MDNavigationDrawer:
id: nav_drawer
BoxLayout:
orientation: 'vertical'
spacing: '8dp'
padding: '8dp'
MDCard:
size_hint: None, None
size: 170,200
pos_hint: {'center_x':0.5, 'center_y':0.8}
Image:
source: 'happydude.jpg'
MDLabel:
text: 'John Doe'
font_style: 'Subtitle1'
size_hint_y: None
height: self.texture_size[1]
theme_text_color: 'Custom'
text_color: (241/255,196/255,15/255,0.8)
MDLabel:
text: 'jonh83e#outlook.com'
font_style: 'Caption'
size_hint_y: None
height: self.texture_size[1]
theme_text_color: 'Custom'
text_color: (241/255,196/255,15/255,0.8)
ScrollView:
MDList:
OneLineIconListItem:
text: 'Profile'
theme_text_color: 'Custom'
text_color: (241/255,196/255,15/255,0.8)
on_press: screen_manager.current = "profile"
IconLeftWidget:
icon: 'face-profile-woman'
OneLineIconListItem:
text: 'Upload'
theme_text_color: 'Custom'
text_color: (241/255,196/255,15/255,0.8)
on_press: screen_manager.current = "upload"
IconLeftWidget:
icon: 'file-upload'
OneLineIconListItem:
text: 'Logout'
theme_text_color: 'Custom'
text_color: (241/255,196/255,15/255,0.8)
IconLeftWidget:
icon: 'logout'
Screen:
id: upload
name: 'upload'
MDLabel:
text: 'Lets upload some files'
halign: 'center'
MDRectangleFlatButton:
text: 'Back'
pos_hint: {'center_x': 0.5, 'center_y': 0.2}
on_press: screen_manager.current = 'main_app_screen'
Screen:
id: messages
name: 'messages'
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Messages Center"
MDIconButton:
icon: 'keyboard-return'
on_press: screen_manager.current = "main_app_screen"
theme_text_color: 'Custom'
md_bg_color: app.theme_cls.primary_color
# Im trying to add it here below:
ScrollView:
MDList:
id: container
#Widget:
After not giving up, I finally found the issue. By default the text color was white, same as the color of the screen. I had to change the color of my text, and to do so I used the parameters ---> OneLineListItem(theme_text_color="Custom",
text_color=(241 / 255, 196 / 255, 15 / 255, 0.8))
Related
I followed the steps in KivyMD documentation to create a NavigationDrawer, so, I created it and everything work correctely, but the problem is to return to the first screen. I want to go back to the first screen (the Screen with name: 'main') when I click in the arrow-left in the MDToolbar, but nothing that I did worked.
KV File:
<ItemDrawer>:
theme_text_color: 'Custom'
on_release: self.parent.set_color_item(self)
IconLeftWidget:
id: icon
icon: root.icon
theme_text_color: 'Custom'
text_color: root.text_color
<ContentNavigationDrawer>:
orientation: 'vertical'
padding: '8dp'
spacing: '8dp'
AnchorLayout:
anchor_x: 'left'
size_hint_y: .3
ScrollView:
MDList:
OneLineIconListItem:
text: 'Reminders'
on_press:
root.nav_drawer.set_state('close')
root.screen_manager.current = 'RemindersWindow'
IconLeftWidget:
icon: 'bookmark-outline'
OneLineIconListItem:
text: 'To Do'
on_press:
root.nav_drawer.set_state('close')
root.screen_manager.current = 'ToDoWindow'
IconLeftWidget:
icon: 'check-outline'
OneLineIconListItem:
text: 'Settings'
on_press:
root.nav_drawer.set_state('close')
root.screen_manager.current = 'SettingsWindow'
IconLeftWidget:
icon: 'cog-outline'
OneLineIconListItem:
text: 'About'
on_press:
root.nav_drawer.set_state('close')
root.screen_manager.current = 'AboutWindow'
IconLeftWidget:
icon: 'information-outline'
Screen:
MDNavigationLayout:
ScreenManager:
id: screen_manager
Screen:
name: 'main'
MDToolbar:
title: 'Remindy'
elevation: 10
pos_hint: {'top': 1}
left_action_items: [["menu", lambda x: nav_drawer.set_state('open')]]
MainScreen:
Screen:
name: 'SettingsWindow'
FloatLayout:
orientation: 'vertical'
MDToolbar:
title: 'Settings'
elevation: 10
pos_hint: {'top': 1}
left_action_items: [["arrow-left", lambda x: x]]
OneLineIconListItem:
text: 'Themes'
pos_hint: {'center_x': .5, 'y': .8}
on_release: app.picker_theme()
IconLeftWidget
icon: 'palette-outline'
OneLineIconListItem:
text: 'Language'
pos_hint: {'center_x': .5, 'y': .7}
on_release:
IconLeftWidget:
icon: 'earth'
Screen:
name: 'RemindersWindow'
FloatLayout:
orientation: 'vertical'
MDToolbar:
elevation: 10
pos_hint: {'top': 1}
left_action_items: [["arrow-left", lambda x: x]]
MDLabel:
text: 'My Reminders'
halign: 'center'
Screen:
name: 'AboutWindow'
FloatLayout:
orientation: 'vertical'
MDToolbar:
elevation: 10
pos_hint: {'top': 1}
left_action_items: [["arrow-left", lambda x: x]]
MDLabel:
text: 'About'
halign: 'center'
Screen:
name: 'ToDoWindow'
FloatLayout:
orientation: 'vertical'
MDToolbar:
elevation: 10
pos_hint: {'top': 1}
left_action_items: [["arrow-left", lambda x: x]]
MDLabel:
text: 'To-Do'
halign: 'center'
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
screen_manager: screen_manager
nav_drawer: nav_drawer
<MainScreen#FloatLayout>:
name: 'MainScreen'
FloatLayout:
orientation: 'vertical'
MDFloatingActionButton:
icon: 'pencil-plus-outline'
pos_hint: {'x': .8, 'y': .1/2}
on_release: root.datacard()
<CardScreen>:
FloatLayout:
orientation: 'vertical'
MDCard:
size_hint: .8, .1
MDLabel:
id: base_label
text: 'New Reminder'
<CardBox>:
orientation: 'vertical'
size_hint: .7, .5
pos_hint: {'center_x': .5, 'center_y': .5}
MDBoxLayout:
size_hint_y: .5
md_bg_color: app.theme_cls.primary_color
MDLabel:
text: 'Add a Reminder'
font_style: 'H6'
theme_text_color: 'Custom'
text_color: 1, 1, 1, 1
halign: 'center'
MDIconButton:
icon: 'window-close'
on_release: root.closecard()
MDFloatLayout:
MDTextField:
id: title_id
hint_text: 'Title'
max_text_length: 15
required: True
helper_text_mode: 'on_error'
helper_text: 'This Field is Required.'
size_hint_x: .8
pos_hint: {'center_x': .5, 'y': .1}
MDFloatLayout:
orientation: 'horizontal'
MDRectangleFlatIconButton:
icon: 'clock-time-four-outline'
text: 'Hour'
pos_hint: {'x': .1, 'y': .3}
on_release: root.picker_hora()
MDRectangleFlatIconButton:
icon: 'calendar-outline'
text: 'Date'
pos_hint: {'x': .6, 'y': .3}
on_release: root.picker_data()
MDFloatLayout:
MDRectangleFlatButton:
text: 'Add'
size_hint_x: .8
pos_hint: {'center_x': .5, 'y': .2}
Python File:
import pickle
from kivy.app import App
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivymd.uix.toolbar import MDToolbar
from kivy.properties import ObjectProperty
from kivymd.uix.list import StringProperty
from kivymd.theming import ThemableBehavior
from kivymd.uix.list import OneLineIconListItem
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.uix.floatlayout import FloatLayout
from kivymd.uix.picker import MDThemePicker
from kivymd.uix.picker import MDTimePicker
from kivymd.uix.picker import MDDatePicker
from kivymd.uix.list import MDList
from kivymd.uix.card import MDCard
class ItemDrawer(OneLineIconListItem):
icon = StringProperty()
class ContentNavigationDrawer(BoxLayout):
screen_manager = ObjectProperty()
nav_drawer = ObjectProperty()
class MainScreen(FloatLayout):
def datacard(self):
self.add_widget(CardBox())
class CardBox(MDCard):
def closecard(self):
self.parent.remove_widget(self)
def picker_hora(self):
time_dialog = MDTimePicker()
time_dialog.open()
def picker_data(self):
date_dialog = MDDatePicker()
date_dialog.open()
def new_card(self):
# Remove and Create a New Card
self.parent.remove_widget(self)
title = self.ids.title_input.text
self.add_widget(CardScreen())
App.get_running_app().root.ids.base_label.text = title
class CardScreen(FloatLayout):
pass
class ReminderApp(MDApp):
Window.size = (400, 600)
def picker_theme(self):
theme_dialog = MDThemePicker()
theme_dialog.open()
def build(self):
return Builder.load_string(KV)
ReminderApp().run()
You need to trigger some action from the button associated to MDToolbar to switch to another screen.
For simple usage you can use the default function setattr as,
left_action_items: [["arrow-left", lambda *args : setattr(screen_manager, "current", "main")]]
Or for advanced usage you can refer to a function from some relevant class say, the App's subclass, as,
left_action_items: [["arrow-left", app.go_home]]
Now in that method,
def go_home(self, *args):
# Access the `ScreenManager` and change the screen.
self.root.ids.screen_manager.current = "main"
# Some other actions.
Also as a side note, you should change the line <MainScreen#FloatLayout> in kvlang with just <MainScreen> as you already defined it in .py. Otherwise a warning may be raised in log.
from kivymd.app import MDApp
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.properties import ObjectProperty
class ContentNavigationDrawer(BoxLayout):
"""This class manage the navigation drawer contents"""
screen_manager = ObjectProperty()
nav_drawer = ObjectProperty()
class MyApp(MDApp):
def build(self):
"""Return the main kivy file and set themes """
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = 'BlueGray'
self.theme_cls.accent_palette = "Teal"
return Builder.load_file("main.kv")
MyApp().run()
and the kv file
<ContentNavigationDrawer>:
MDBoxLayout:
orientation: "vertical"
spacing: dp("8")
padding: dp("8")
ScrollView:
MDList:
OneLineIconListItem:
text: "hexagon"
on_press:
root.nav_drawer.set_state("close")
root.screen_manager.current = "mainScreen"
IconLeftWidget:
icon: 'hexagon'
MDScreen:
MDToolbar:
id: toolbar
title: "Hexagon"
md_bg_color: app.theme_cls.primary_color
specific_text_color: 1, 1, 1, 1
pos_hint: {"top": 1}
elevation: 9
icon: 'account-circle'
left_action_items: [["menu", lambda x: nav_drawer.set_state("open")]]
MDNavigationLayout:
x: toolbar.height
ScreenManager:
id: screen_manager
MDScreen:
name: "mainScreen"
BoxLayout:
orientation: 'vertical'
size: root.width, root.height
ScrollView:
do_scroll_x: True
do_scroll_y: True
size_hint: (1, .85)
bar_width: 10
bar_color: (1, 0, 0 ,1)
scroll_type: ["bars", "content"]
pos_hint: {'top': 1.0 - toolbar.height/float(root.height)}
GridLayout:
id: labels_layout
size_hint_y: None
height:self.minimum_height
size_hint_x: None
width: self.minimum_width
cols: 1
spacing: "5dp"
padding: "5dp"
MDLabel:
id: big_text_label
text: "asldklsa\nasdsaf\nssss\n"
width: self.texture_size[1]
height: self.texture_size[1]
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
screen_manager: screen_manager
nav_drawer: nav_drawer
test_screen_shot
I want to change the color of the toolbar I tried almost everything to do it
like md_bg_color: app.theme_cls.primary_color and md_bg_color: .2, .2, .2, 1
And the text goes beyond the boundaries even of the app if i add some widgets to get back
text to its area the it goes under the toolbar
Using:
Python 3.9, dev kivyMD 2.0, editor pycharm
Use:
from kivymd.app import MDApp
from kivy.lang import Builder
KV = """
<ContentNavigationDrawer>:
MDBoxLayout:
orientation: "vertical"
spacing: dp("8")
padding: dp("8")
ScrollView:
MDList:
OneLineIconListItem:
divider: None
text: "hexagon"
on_press:
app.root.ids.nav_drawer.set_state("toggle")
#root.screen_manager.current = "mainScreen"
IconLeftWidget:
icon: 'account'
## BoxLayout:
## canvas.before:
## Color:
## rgba: [1,.3,0,1]
## Line:
## width: dp(1)
## rounded_rectangle:
## (self.x, self.y, self.width-dp(20), dp(43),\
## dp(12),dp(12),dp(12),dp(12),\
## dp(50))
OneLineIconListItem:
divider: None
text: "hexagon"
on_press:
app.root.ids.nav_drawer.set_state("toggle")
#root.screen_manager.current = "mainScreen"
IconLeftWidget:
icon: 'hexagon'
OneLineIconListItem:
divider: None
text: "Edit"
on_press:
app.root.ids.nav_drawer.set_state("toggle")
#root.screen_manager.current = "mainScreen"
IconLeftWidget:
icon: 'pencil'
OneLineIconListItem:
divider: None
text: "Home"
on_press:
app.root.ids.nav_drawer.set_state("toggle")
#root.screen_manager.current = "mainScreen"
IconLeftWidget:
icon: 'home'
OneLineIconListItem:
divider: None
text: "Likes"
on_press:
app.root.ids.nav_drawer.set_state("toggle")
#root.screen_manager.current = "mainScreen"
IconLeftWidget:
icon: 'star'
OneLineIconListItem:
divider: None
text: "hexagon"
on_press:
app.root.ids.nav_drawer.set_state("toggle")
#root.screen_manager.current = "mainScreen"
IconLeftWidget:
icon: 'hexagon'
OneLineIconListItem:
divider: None
text: "Search"
on_press:
app.root.ids.nav_drawer.set_state("toggle")
#root.screen_manager.current = "mainScreen"
IconLeftWidget:
icon: 'magnify'
Screen:
MDToolbar:
id: toolbar
pos_hint: {"top": 1}
title: "Hexagon"
md_bg_color: [1,0,0,1]
specific_text_color: [1, 1, 1, 1]
elevation: 0
left_action_items: [["menu", lambda x: nav_drawer.set_state("toggle")]]
right_action_items: [["account-circle", lambda x: print(222)]]
ScreenManager:
id: screen_manager
MDScreen:
name: "mainScreen"
FloatLayout:
BoxLayout:
id: m5
pos_hint: {"center_x": .5, "center_y": .38} #this will change if you change this Window.size = (330, 500)
orientation: "vertical"
ScrollView:
do_scroll_x: False #True
do_scroll_y: True
#size_hint: (1, .85)
bar_width: 10
bar_color: (1, 0, 0 ,1)
scroll_type: ["bars", "content"]
pos_hint: {'top': 1.0 - toolbar.height/float(root.height)}
GridLayout:
id: labels_layout
size_hint_y: None
height:self.minimum_height
size_hint_x: 1
#width: self.minimum_width
cols: 1
spacing: "5dp"
padding: dp(20)
MDLabel:
id: big_text_label
text: "\\n\\n\\n\\n\\n\\nWelcome to this New App.\\nYou will get a lot of benefits.\\n\\njbsidis recommendations are good so we can design in different ways."
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
screen_manager: screen_manager
"""
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
class ContentNavigationDrawer(BoxLayout):
"""This class manage the navigation drawer contents"""
screen_manager = ObjectProperty()
#nav_drawer = ObjectProperty()
class WeatherApp(MDApp):
def __init__(self, **kwargs):
super().__init__(**kwargs)
pass
def build(self):
self.screen = Builder.load_string(KV)
return self.screen
WeatherApp().run()
Pictures:
I think this problem is easy to solve, but i dont have experience enough to do this.
So, I want to reference the input text (MDTextField on kv file) for the variable "name" that is inside the press() function, so that I can write inside the popup.
I'm learning kivymd for a college project, so, discount the errors and unnecessary informations :/
Here is my kv file
Screen:
id: screen1
NavigationLayout:
id: navigation
ScreenManager:
id: screen_manager
Screen:
id: fact
name: 'fact'
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Menu"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.set_state()]]
Widget:
MDLabel:
text: "Fact Checker"
font_size: 56
font_name: "MontserratBold"
pos_hint: {'center_x': 0.75, 'center_y': 0.7}
theme_text_color: "Custom"
text_color: (53/255, 183/255, 1, 1)
MDTextField:
id: input_box
hint_text: "Type here"
font_size: 18
pos_hint: {'center_x': 0.5, 'center_y': 0.45}
size_hint_x: None
width: 500
multiline: True
helper_text: "Type the title of the news"
helper_text_mode: "on_focus"
theme_text_color: "Custom"
text_color: (53/255, 183/255, 1, 1)
line_color_normal: 1, 1, 1, 1
MDRectangleFlatButton:
text: "Check"
pos_hint: {'center_x': 0.5, 'center_y': 0.25}
theme_text_color: "Custom"
text_color: (1, 1, 1, 1)
on_press: app.press()
MDLabel:
markup: True
text: "<Developed by: [color=#cfd0d1]Caio Barreto and Gabriel Queiroz[/color]>"
font_name: "Montserrat"
theme_text_color: "Custom"
text_color: (53/255, 183/255, 1, 0.5)
pos_hint: {'center_x': 0.74, 'center_y': 0.1}
Screen:
name: 'discord'
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Menu"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.set_state()]]
Widget:
MDLabel:
text: 'teste1'
Screen:
name: 'add'
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Menu"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.set_state()]]
Widget:
MDLabel:
text: 'teste2'
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
ScrollView:
DrawerList:
id: md_list
MDList:
OneLineIconListItem:
text: "Menu"
on_press: screen_manager.current = "fact"
IconLeftWidget:
icon: "home"
OneLineIconListItem:
text: "Discord"
on_press: screen_manager.current = "discord"
IconLeftWidget:
icon: "discord"
OneLineIconListItem:
text: "Add more news"
on_press: screen_manager.current = "add"
IconLeftWidget:
icon: "circle-edit-outline"
Here is my python code:
from kivymd.app import MDApp
from kivy.lang.builder import Builder
from kivymd.uix.dialog import MDDialog
from kivymd.uix.textfield import MDTextField
from kivymd.uix.button import MDRectangleFlatButton, MDFlatButton
from kivymd.uix.navigationdrawer import NavigationLayout
from kivymd.uix.list import MDList
from kivymd.uix.boxlayout import BoxLayout
from kivymd.theming import ThemableBehavior
from kivy.core.text import LabelBase
from kivy.uix.widget import Widget
from helper import username_input
from kivymd.uix.screen import Screen
LabelBase.register(name="MontserratBold", fn_regular="font/Montserrat-Bold.ttf")
LabelBase.register(name="Montserrat", fn_regular="font/Montserrat-Medium.ttf")
class FactCheckerApp(MDApp):
class ContentNavigationDrawer(BoxLayout):
pass
class DrawerList(ThemableBehavior, MDList):
pass
def build(self):
self.file = Builder.load_file('projeto.kv')
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "LightBlue"
print(self.file.Screen.ids.)
return self.file
def press(self):
name = self.screen1.navigation.screen_manager.fact.input_box.text
close_button = MDFlatButton(text='Close', on_release=self.close_dialog)
self.dialog = MDDialog(title='Answer', text=name, size_hint=(0.5, 1), buttons=[close_button])
self.dialog.open()
def close_dialog(self, obj):
self.dialog.dismiss()
if __name__ == '__main__':
FactCheckerApp().run()
To access the MDTextField, you can just reference it through its id, which is defined in the widget that is the root of the kv rule where the id is defined (in this case, in the Screen). Try changing:
name = self.screen1.navigation.screen_manager.fact.input_box.text
to:
name = self.root.ids.input_box.text
in the press() method.
Here is a picture of the problem. As you can see the left side picture has a fully working scrollview, the rightside picture on the other hand is only displaying the scrollview on the bottom half of the screen.
Not sure whats wrong here. Ive tried moving the intendent levels back and forth, for some reason it refuses to put anything above the equator
Snippit of the KV code from the not working part:
Screen:
container: container
BoxLayout:
id: container
orientation: 'vertical'
MDToolbar:
title: "TRYM"
anchor_title: "center"
# right_action_items: [["check", lambda x: app.show_alert_dialog_save(), 'Save']]
left_action_items: [["keyboard-backspace", lambda x: app.show_alert_dialog_back(), 'Back']]
Widget:
ScreenManager:
id: screen_manager
Screen:
name: 'innlogget_trym_alarm'
id: trym
MDBottomNavigation:
MDBottomNavigationItem:
name: 'alarm_trym'
text: 'Alarm'
icon: 'alarm'
on_tab_release: text: 'Alarm'
MDLabel:
text: 'Currently no alarm active'
pos_hint: {"center_x": .5, "center_y": .8}
halign: 'center'
MDFloatingActionButton:
id: trym_time_picker
name: 'trym'
icon: "alarm-plus"
opposite_colors: False
elevation_normal: 8
pos_hint: {"center_x": .9, "center_y": .2}
on_release:
app.show_time_picker('trym')
MDBottomNavigationItem:
name: 'instillinger_trym'
text: 'Instillinger'
icon: 'tools'
# on_tab_release: screen_manager.current = "settings_list_view"
MDLabel:
ScrollView:
MDList:
OneLineIconListItem:
text: "Oppgrader til premium"
on_release:
print("Click!")
IconLeftWidget:
icon: "lock-outline"
TwoLineIconListItem:
text: "Tilkoblingsinnstillinger"
secondary_text: "Endre IP og port for klientsiden"
on_release:
app.show_confirmation_dialog()
IconLeftWidget:
icon: "lan-connect"
TwoLineIconListItem:
text: "Alarminstillinger"
secondary_text: "Konfigurer forsinket eller for tidlig handling"
on_release:
print("Click!")
IconLeftWidget:
icon: "account-clock"
Snippit of the KV code from the working part:
MDNavigationDrawer:
id: nav_draw
orientation: "vertical"
padding: "8dp"
spacing: "8dp"
AnchorLayout:
anchor_x: "center"
size_hint_y: None
height: avatar.height
Image:
id: avatar
size_hint: None, None
size: "56dp", "56dp"
source: "untitled.jpg"
MDLabel:
halign: 'center'
anchor_x: "right"
text: "AnySched"
font_style: "Button"
size_hint_y: None
height: self.texture_size[1]
MDLabel:
text: ""
font_style: "Caption"
size_hint_y: None
height: self.texture_size[1]
ScrollView:
MDList:
OneLineAvatarListItem:
on_press:
nav_draw.set_state("close")
app.next_screen('trym')
text: "Trym"
IconLeftWidget:
icon: "account-box"
OneLineAvatarListItem:
on_press:
nav_draw.set_state("close")
screen_manager.current = "lucas"
So I found the problem (posting incase anyone else gets the same issue).
Screen:
container: container
BoxLayout:
id: container
orientation: 'vertical'
MDToolbar:
title: "TRYM"
anchor_title: "center"
# right_action_items: [["check", lambda x: app.show_alert_dialog_save(), 'Save']]
left_action_items: [["keyboard-backspace", lambda x: app.show_alert_dialog_back(), 'Back']]
Widget: # <----- After removing this the ScrollView fills the whole screen not just half :)
ScreenManager:
id: screen_manager
Screen:
name: 'innlogget_trym_alarm'
id: trym
MDBottomNavigation:
I'm having trouble finding the solution in how to remove an expansion panel which inside of it it contains TwoLineAvatarListItem with a IconLeftWidget, and below that is a MDCard with two MDlabels for text. I've tried to use self.root.ids.remove_widget() but it does not do anything. I've tried many ways and have not found the solution. Here is the code please feel free to view. Thanks
kv. file
<Content>:
adaptive_height: True
#size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
TwoLineAvatarListItem:
text: "Message"
secondary_text: 'to: #gmail.com'
IconLeftWidget:
icon: 'email'
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: "Body"
ScreenManager:
Screen:
id: messages
name: 'messages'
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Messages Center"
elevation:8
MDIconButton:
icon: 'arrow-left'
on_press: screen_manager.current = "main_app_screen"
theme_text_color: 'Custom'
md_bg_color: app.theme_cls.primary_color
ScrollView:
GridLayout:
cols: 1
size_hint_y: None
height: self.minimum_height
id: box
.py python file
class DemoApp(MDApp):
def on_start(self):
for i in range(10):
panel = MDExpansionPanel(
icon=f"{images_path}folder.png",
content=Content(),
panel_cls=MDExpansionPanelTwoLine(
text='',
secondary_text=str(i) + ' email: xxxxx#gmail.com',))
self.root.ids.box.add_widget(panel)
DemoApp().run()
<Content>:
[...]
MDCard:
[...]
MDRaisedButton:
text: "REMOVE"
on_release: app.remove(root)
[...]
class DemoApp(MDApp):
[...]
def remove(self, content):
self.root.ids.box.remove_widget(content.parent)