how to change screen to a screen with kivymd bottomnavigation - python-3.x

I added KivyMD BottomNavigation to my App, I am able to switch screens with icon, but the issue is switching back to a screen containing the BottomNavigation
(let's say we in any of the screens containing Toolbar and BottomNavigation, we use the toolbar to switch to a entirely different screen, I am unable to go back to the previous screen or even navigate to any of thr screens containing the bottomnavigation and toolbar, it returns a blank white screen).
Despite naming the screen, so my question is; 1. am I refering (naming) the BottomNavigationItem wrongly, if yes please what should I change. (2) is there something am missing, please let me know.
Thank you.
here's my main.py file
from kivymd.app import MDApp
from kivy.uix.screenmanager import Screen, ScreenManager, NoTransition
from kivy.core.window import Window
Window.size = (300, 530)
class MainScreen(Screen):
pass
class IntroScreen(Screen):
pass
class WaysScreen(Screen):
pass
class To_DoScreen(Screen):
pass
class SuccessScreen(Screen):
pass
class GoalsScreen(Screen):
pass
class BellaBaron(Screen):
pass
class SearchScreen(Screen):
pass
class MenuScreen(Screen):
pass
class CalendarScreen(Screen):
pass
class ExtraScreen(Screen):
pass
class ArchiveScreen(Screen):
pass
class Contact_InfoScreen(Screen):
pass
class TenThousandApp(MDApp):
def build(self):
self.theme_cls.primary_palette = 'Green'
self.theme_cls.primary_hue = '200'
# self.theme_cls.theme_style = 'Light'
self.sm = ScreenManager(transition=NoTransition())
self.sm.add_widget(MainScreen(name="main_screen"))
self.sm.add_widget(IntroScreen(name="intro_screen"))
self.sm.add_widget(WaysScreen(name="ways_screen"))
self.sm.add_widget(To_DoScreen(name="to_do_screen"))
self.sm.add_widget(SuccessScreen(name="success_screen"))
self.sm.add_widget(GoalsScreen(name="goals_screen"))
self.sm.add_widget(BellaBaron(name="bella_baron"))
self.sm.add_widget(SearchScreen(name="search_screen"))
self.sm.add_widget(MenuScreen(name="menu_screen"))
self.sm.add_widget(CalendarScreen(name="calendar_screen"))
self.sm.add_widget(ExtraScreen(name="extra_screen"))
self.sm.add_widget(ArchiveScreen(name="archive_screen"))
self.sm.add_widget(Contact_InfoScreen(name="contact_info_screen"))
return self.sm
def change_screen(self, screen):
self.sm.current = screen
TenThousandApp().run()
and here's my .kv file
# ScreenManager:
#start of imagelist
<MyTile#SmartTileWithLabel>
size_hint_y: None
height: "240dp"
<MainScreen>:
MDBottomNavigation:
# panel_color: .2, .2, .2, 1
MDBottomNavigationItem:
name: "intro_screen"
text: 'home'
icon: 'home'
MDBoxLayout:
orientation: 'vertical'
# md_bg_color: app.theme_cls.bg_dark
MDToolbar:
id: intro_screen_toolbar
title: '[font=Gabriola][size=40][color=#FD0101]First[/color][/size][size=28]project[/size][/font]'
right_action_items: [["calendar-month", lambda x: app.change_screen('to_do_screen')]] #links to to-do listss screen
elevation: "8dp"
MDCard:
orientation: 'vertical'
padding: 16
size_hint: None, None
size: "280dp", "360dp"
pos_hint: {"center_x": .5, "center_y": .6}
height: root.height - intro_screen_toolbar.height - dp(55)
y: root.height - intro_screen_toolbar.height - dp(50)
elevation: "8dp"
orientation: 'vertical'
radius: 15
ScrollView:
MDLabel:
markup: True
size_hint_y: None
size: self.texture_size
text:
"""[b][i]“Your time is limited, so don’t waste it living someone else’s life. Don’t be trapped by dogma – which is living with the results of other people’s thinking. Don’t let the noise of other’s opinions drown out your own inner voice. And most important, have the courage to follow your heart and intuition. They somehow already know what you truly want to become. Everything else is secondary.”[/i][/b]
– Steve Jobs"""
MDBottomNavigationItem:
name: "success_screen"
text: 'home'
icon: 'account-group'
BoxLayout:
orientation: 'vertical'
MDToolbar:
id: success_screen_toolbar
title: "Success Stories"
right_action_items: [["progress-clock", lambda x: app.change_screen('goals_screen')]] #links to goals and how screen
elevation: "8dp"
ScrollView:
MDGridLayout:
cols: 1
adaptive_height: True
padding: dp(4), dp(4)
spacing: dp(4)
MyTile:
source: "C:/Users/HP USER/Downloads/bella_baron.jpg"
text: "[size=26]Cat 1[/size]\\n[size=14]cat-1.jpg[/size]"
on_release:
app.root.current = 'bella_baron'
MyTile:
source: "C:/Users/HP USER/Downloads/bella_baron.jpg"
text: "[size=26]Cat 2[/size]\\n[size=14]cat-2.jpg[/size]"
tile_text_color: app.theme_cls.accent_color
MyTile:
source: "C:/Users/HP USER/Downloads/bella_baron.jpg"
text: "[size=26][color=#ffffff]Cat 3[/color][/size]\\n[size=14]cat-3.jpg[/size]"
tile_text_color: app.theme_cls.accent_color
MDBottomNavigationItem:
name: "search_screen"
text: 'search'
icon: 'magnify'
FloatLayout:
MDTextField:
mode: 'fill'
hint_text: "Search"
pos_hint: {"center_x": .5,"center_y": .9}
size_hint_x: None
width: 280
MDBottomNavigationItem:
name: "menu_screen"
text: 'menu'
icon: 'menu'
BoxLayout:
orientation: "vertical"
md_bg_color: (240/255, 240/255, 240/255, 1)
MDToolbar:
id: menu_screen_toolbar
title: "Tools"
elevation: "8dp"
MDCard:
orientation: 'vertical'
padding: 16
size_hint: None, None
size: "280dp", "360dp"
pos_hint: {"center_x": .5, "center_y": .6}
height: root.height - menu_screen_toolbar.height - dp(55)
y: root.height - menu_screen_toolbar.height - dp(50)
elevation: 8
orientation: 'vertical'
radius: 15
ScrollView:
MDList:
OneLineIconListItem:
text: "Calendar"
on_release:
app.root.current = "calendar_screen"
IconLeftWidget:
icon: "calendar-month"
OneLineIconListItem:
text: "Extra"
on_release:
app.root.current = "extra_screen"
IconLeftWidget:
icon: "notebook-multiple"
OneLineIconListItem:
text: "Archive"
on_release:
app.root.current = "archive_screen"
IconLeftWidget:
icon: "archive"
OneLineIconListItem:
text: "contact Us"
on_release:
app.root.current = "contact_info_screen"
IconLeftWidget:
icon: "email-mark-as-unread"
<WaysScreen>
name: "ways_screen"
BoxLayout:
orientation: 'vertical'
MDToolbar:
id: ways_screen_toolbar
title: "How-tos"
left_action_items: [['keyboard-backspace', lambda x: app.change_screen('intro_screen')]] # to add more list
left_action_items: [['keyboard-backspace', lambda x: app.change_screen('intro_screen')]]
elevation: "8dp"
ScrollView:
MDGridLayout:
cols: 1
adaptive_height: True
spacing: 10
padding: 10
MDCard:
size_hint: None, None
size: "280dp", "130dp"
radius: 15
Image:
source: "C:/Users/HP USER/Downloads/bella_baron.jpg"
MDCard:
size_hint: None, None
size: "280dp", "130dp"
radius: 15
caption: 'Hello dear'
ScrollView:
MDLabel:
size_hint_y: None
size: self.texture_size
# halign: 'center'
text:
"""This screens contains a MDcard which where the image is placed, and a MDLabel and neccessary widgets used to tell the success story, under the MDCard."""
MDCard:
size_hint: None, None
size: "280dp", "130dp"
radius: 15
caption: 'Hello boss'
MDCard:
size_hint: None, None
size: "280dp", "130dp"
radius: 15
caption: 'Hello goodness'
MDCard:
size_hint: None, None
size: "280dp", "130dp"
radius: 15
caption: 'Hello hi'
MDCard:
size_hint: None, None
size: "280dp", "130dp"
radius: 15
caption: 'Hello yes?'
<To_DoScreen>
name: "to_do_screen"
BoxLayout:
orientation: 'vertical'
MDToolbar:
id: to_do_screen_toolbar
title: 'To-Do-List'
right_action_items: [['plus', lambda x: x]] # to add more list
left_action_items: [['keyboard-backspace', lambda x: app.change_screen('intro_screen')]]
elevation: "8dp"
MDCard:
orientation: 'vertical'
padding: 16
elevation: 8
radius: 15
size_hint: None, None
size: '280', '360'
pos_hint: {"center_x": .5, "center_y": .6}
height: root.height - to_do_screen_toolbar.height + dp(10)
y: root.height - to_do_screen_toolbar.height - dp(20)
<GoalsScreen>
name: 'goals_screen'
BoxLayout:
orientation: 'vertical'
MDToolbar:
id: goals_screen_toolbar
title: 'Goals'
left_action_items: [['keyboard-backspace', lambda x: app.change_screen('success_screen')]]
elevation: "8dp"
MDCard:
orientation: 'vertical'
padding: 16
size_hint: None, None
size: "280dp", "360dp"
pos_hint: {"center_x": .5, "center_y": .6}
height: root.height - goals_screen_toolbar.height + dp(10)
y: root.height - goals_screen_toolbar.height - dp(20)
elevation: "8dp"
orientation: 'vertical'
radius: 15
<BellaBaron>
name: 'bella_baron'
BoxLayout:
orientation: 'vertical'
md_bg_color: (240/255, 240/255, 240/255, 1)
MDToolbar:
id: bella_baron_toolbar
title: "Bella Baron"
left_action_items: [["keyboard-backspace", lambda x: app.change_screen('success_screen')]]
right_action_items: [["progress-check", lambda x: app.change_screen('goals_screen')]] #link to progress screen
elevation: "8dp"
ScrollView:
MDGridLayout:
cols: 1
adaptive_height: True
spacing: 10
padding: 10
MDCard:
size_hint: None, None
size: "280dp", "130dp"
radius: 15
Image:
source: "C:/Users/HP USER/Downloads/bella_baron.jpg"
MDCard:
size_hint: None, None
size: "280dp", "130dp"
radius: 15
caption: 'Hello dear'
ScrollView:
MDLabel:
size_hint_y: None
size: self.texture_size
# halign: 'center'
text:
"""This screens contains a MDcard which where the image is placed, and a MDLabel and neccessary widgets used to tell the success story, under the MDCard."""
MDCard:
size_hint: None, None
size: "280dp", "130dp"
radius: 15
caption: 'Hello boss'
MDCard:
size_hint: None, None
size: "280dp", "130dp"
radius: 15
caption: 'Hello goodness'
MDCard:
size_hint: None, None
size: "280dp", "130dp"
radius: 15
caption: 'Hello hi'
MDCard:
size_hint: None, None
size: "280dp", "130dp"
radius: 15
caption: 'Hello yes?'
<CalendarScreen>
name: "calendar_screen"
BoxLayout:
orientation: 'vertical'
MDToolbar:
id: calendar_screen_toolbar
title: 'Calendar'
left_action_items: [['keyboard-backspace', lambda x: app.change_screen('menu_screen')]]
right_action_items: [['calendar', lambda x: x]] # on press returns today's date
elevation: "8dp"
MDCard:
orientation: 'vertical'
padding: 16
elevation: 8
radius: 15
size_hint: None, None
size: '280', '360'
pos_hint: {"center_x": .5, "center_y": .6}
height: root.height - calendar_screen_toolbar.height + dp(10)
y: root.height - calendar_screen_toolbar.height - dp(20)
# I will remove this screen if there is no need for it.
<ExtraScreen>
name: "extra_screen"
BoxLayout:
orientation: 'vertical'
MDToolbar:
id: extra_screen_toolbar
title: 'Extra'
left_action_items: [['keyboard-backspace', lambda x: app.change_screen('menu_screen')]]
elevation: "8dp"
ScrollView:
MDGridLayout:
cols: 1
adaptive_height: True
spacing: 10
padding: 10
MDCard:
size_hint: None, None
size: "280dp", "130dp"
radius: 15
Image:
source: "C:/Users/HP USER/Downloads/bella_baron.jpg"
MDCard:
size_hint: None, None
size: "280dp", "130dp"
radius: 15
caption: 'Hello dear'
ScrollView:
MDLabel:
size_hint_y: None
size: self.texture_size
# halign: 'center'
text:
"""This screens contains a MDcard which where the image is placed, and a MDLabel and neccessary widgets used to tell the success story, under the MDCard."""
MDCard:
size_hint: None, None
size: "280dp", "130dp"
radius: 15
caption: 'Hello boss'
MDCard:
size_hint: None, None
size: "280dp", "130dp"
radius: 15
caption: 'Hello goodness'
MDCard:
size_hint: None, None
size: "280dp", "130dp"
radius: 15
caption: 'Hello hi'
MDCard:
size_hint: None, None
size: "280dp", "130dp"
radius: 15
caption: 'Hello yes?'
<ArchiveScreen>
name: "archive_screen"
BoxLayout:
orientation: 'vertical'
MDToolbar:
id: archive_screen_toolbar
title: 'Archive'
left_action_items: [['keyboard-backspace', lambda x: app.change_screen('menu_screen')]]
elevation: "8dp"
MDCard:
orientation: 'vertical'
padding: 16
elevation: 8
radius: 15
size_hint: None, None
size: '280', '360'
pos_hint: {"center_x": .5, "center_y": .6}
height: root.height - archive_screen_toolbar.height + dp(10)
y: root.height - archive_screen_toolbar.height - dp(20)
<Contact_InfoScreen>
name: "contact_info_screen"
BoxLayout:
orientation: 'vertical'
MDToolbar:
id: contact_info_screen_toolbar
title: 'Contact Info'
left_action_items: [['keyboard-backspace', lambda x: app.change_screen('menu_screen')]]
elevation: "8dp"
MDCard:
orientation: 'vertical'
padding: 16
elevation: 8
radius: 15
size_hint: None, None
size: '280', '360'
pos_hint: {"center_x": .5, "center_y": .6}
height: root.height - contact_info_screen_toolbar.height + dp(10)
y: root.height - contact_info_screen_toolbar.height - dp(20)
ScrollView:
MDLabel:
size_hint_y: None
size: self.texture_size
text:
"""feel free to reach us #"""

To change to a different MDBottomNavigationItem in a MDBottomNavigation, you should use the switch_tab() method of MDBottomNavigation. You can add a method to your TenThousandApp class:
def change_screen_item(self, nav_item):
# change to the MainScreen and switch to the spcified MDBottomNavigationItem
s = self.sm.get_screen('main_screen')
s.ids.bottom_nav.switch_tab(nav_item)
self.sm.current = 'main_screen'
In your kv, you must add an id for the MDBottomNavigation:
<MainScreen>:
MDBottomNavigation:
id: bottom_nav
# panel_color: .2, .2, .2, 1
That id is used to access the MDBottomNavigation instance.
Then in the kv, you can use the change_screen_item() to switch to the MainScreen and switch to the specified MDBottomNavigationItem, like this:
<CalendarScreen>
name: "calendar_screen"
BoxLayout:
orientation: 'vertical'
MDToolbar:
id: calendar_screen_toolbar
title: 'Calendar'
left_action_items: [['keyboard-backspace', lambda x: app.change_screen_item('intro_screen')]]
right_action_items: [['calendar', lambda x: x]] # on press returns today's date
elevation: "8dp"
The above code will switch to the intro_screen item of the MainScreen.

Related

How to change widget's child layout at runtime using python kivy?

How can I change layout of MDBoxLayout, id: body_box in MsgCard, remove MDLabel, id: msg_count then add Checkbox, id: flagged in place at runtime? Here's the kivy file...
<MsgCard#MDBoxLayout>:
id: msg_container
adaptive_height: True
spacing: dp(10)
padding: (dp(5),)*4
FitImage:
id: msg_image
source: root.avatar
size_hint: 0.09, None
height: dp(30)
pos_hint: {"top": 1}
radius: (10,)*4
MDBoxLayout:
orientation: "vertical"
MDBoxLayout:
MDLabel:
text: root.sender
font_style: "Subtitle2"
MDLabel:
text: root.received
font_size: "12sp"
halign: "right"
size_hint_x: 0.25
MDBoxLayout:
id: body_box
MDLabel:
text: root.body
shorten: True
shorten_from: "right"
font_style: "Caption"
MDLabel:
id: msg_count
text: root.count
size_hint: None, None
post_hint: {"center_y": 0.5}
size: (dp(17),)*2
font_size: "12sp"
halign: "center"
theme_text_color: "Custom"
text_color: 1,1,1,1
opacity: 1 if root.count != "0" else 0
canvas.before:
Color:
rgba: 1,0,0,1
RoundedRectangle:
size: self.size
pos: self.pos
radius: (dp(3),)*2
<Checkbox#MDCheckbox>
id: flagged
size_hint: None, None
size: (dp(17),)*2

The home_switch function keeps returning that there is no screen with name "home"

from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.floatlayout import FloatLayout
from kivy.core.window import Window
from kivy.config import Config
from kivy.utils import platform
from kivy.properties import ObjectProperty
import sqlite3
from kivymd.uix.fitimage import FitImage
Window.size = (360, 780)
class Start_Screen(Screen):
pass
class Sign_Up(Screen):
def signup(self):
signup_password = self.signup_password.text
signup_password_re = self.signup_password_re.text
if signup_password != "" and signup_password_re != "":
if signup_password == signup_password_re:
print ("correct")
sm.home_switch()
else:
print ("incorrect")
else:
print ("empty")
class Log_In(Screen):
pass
class Home(Screen):
pass
class WindowManager(ScreenManager):
def home_switch(self, *args):
self.current = "home"
sm = WindowManager()
class MainApp(MDApp):
def build(self):
self.theme_cls.primary_palette = "Yellow"
return Builder.load_file('Vocate.kv')
MainApp().run()
and this is the .kv file
WindowManager:
Start_Screen:
name: "start"
Sign_Up:
name: "sign up"
Log_In:
name: "log in"
Home:
name: "home"
<Sign_Up>:
name: "sign up"
id: signup
signup_phone: signup_phone
signup_password: signup_password
signup_password_re: signup_password_re
MDFloatLayout:
Image:
source: 'images/Vocate.png'
size_hint: 0.6, 0.6
pos_hint: {"center_x": 0.2, "center_y": 0.95}
FloatLayout:
cols: 1
MDTextField:
id: signup_phone
hint_text: "Phone Number"
required: True
font_size: 20
size_hint: 0.9, 0.09
pos_hint: {"center_x": 0.5, "center_y": 0.725}
multiline: False
helper_text: "This Field is Required"
helper_text_mode: "on_error"
MDTextField:
id: signup_password
hint_text: "Password"
required: True
password: True
font_size: 20
size_hint: 0.9, 0.09
pos_hint: {"center_x": 0.5, "center_y": 0.625}
multiline: False
helper_text: "This Field is Required"
helper_text_mode: "on_error"
MDTextField:
id: signup_password_re
hint_text: "Password"
required: True
password: True
font_size: 20
size_hint: 0.9, 0.09
pos_hint: {"center_x": 0.5, "center_y": 0.525}
multiline: False
helper_text: "This Field is Required"
helper_text_mode: "on_error"
MDFillRoundFlatButton:
theme_text_color: "Custom"
md_bg_color: 250/255, 205/255, 62/255, 1
font_size: 20
text_color: 254.99/255, 255/255, 255/255, 1
size_hint: 0.9, 0.06
pos_hint: {"center_x": 0.5, "center_y": 0.425}
text: "Sign Up"
bold: True
on_release:
root.signup()
MDFlatButton:
text: "Go Back"
bold: True
theme_text_color: "Custom"
text_color: 250/255, 205/255, 62/255, 1
font_size: 20
size_hint: 0.9, 0.06
pos_hint: {"center_x": 0.5, "center_y": 0.34}
on_release:
app.root.current = "start"
root.manager.transition.direction = "right"
<Home>:
name: 'home'
MDFloatLayout:
cols: 1
MDBoxLayout:
orientation: "vertical"
MDBottomNavigation:
MDBottomNavigationItem:
name: "home screen"
icon: "home"
MDBoxLayout:
orientation: "vertical"
MDToolbar:
title: "Home"
md_bg_color: 250/255, 205/255, 62/255, 1
specific_text_color: 255/255, 255/255, 255/255, 1
MDLabel:
text: "test 1"
halign: "center"
MDBottomNavigationItem:
name: "courses"
icon: "book-open-variant"
MDFloatLayout:
cols: 2
MDBoxLayout:
orientation: "horizontal"
MDBoxLayout:
orientation: "vertical"
MDToolbar:
md_bg_color: 250/255, 205/255, 62/255, 1
FitImage:
source: "images/coding.png"
FitImage:
source: "images/python.png"
FitImage:
source: "images/gsuite.png"
FitImage:
source: "images/english.png"
FitImage:
source: "images/vocate.png"
FitImage:
source: "images/vocate.png"
MDBoxLayout:
orientation: "vertical"
MDToolbar:
md_bg_color: 250/255, 205/255, 62/255, 1
MDLabel:
text: "Coding - 1"
MDLabel:
text: "Coding - 2"
MDLabel:
text: "Gsuite"
MDLabel:
text: "English"
MDLabel:
text: "Woodworking"
MDLabel:
text: "Customer Service"
MDBoxLayout:
orientation: "vertical"
MDToolbar:
title: "Courses"
md_bg_color: 250/255, 205/255, 62/255, 1
specific_text_color: 255/255, 255/255, 255/255, 1
Button:
background_color: 0, 0, 0, 0
Button:
background_color: 0, 0, 0, 0
Button:
background_color: 0, 0, 0, 0
Button:
background_color: 0, 0, 0, 0
Button:
background_color: 0, 0, 0, 0
Button:
background_color: 0, 0, 0, 0
MDBottomNavigationItem:
name: "more"
icon: "dots-horizontal"
MDBoxLayout:
orientation: "vertical"
MDToolbar:
title: "More"
md_bg_color: 250/255, 205/255, 62/255, 1
specific_text_color: 255/255, 255/255, 255/255, 1
MDLabel:
text: "test 3"
halign: "center"
I've tried changing "WindowManager:" to "" but it returns a blank screen. Some questions similar to this I've seen say to remove the builder and rename the file so I've tried "Main.kv" and "MainApp.kv" and both return the same blank screen.
Thanks in advance!
*Note: I've removed some of the code so that it's clearer so some of the screens and some other stuff that won't interfere here aren't included
The main problem is the line sm = WindowManager() is creating the WindowManager before the Vocate.kv file is loaded. As a result, the sm has no Screens.
A way to fix that is to eliminate the sm = WindowManager() line completely, and use the manager property of a Screen to access the WindowManager. Like this:
class Sign_Up(Screen):
def signup(self):
signup_password = self.signup_password.text
signup_password_re = self.signup_password_re.text
if signup_password != "" and signup_password_re != "":
if signup_password == signup_password_re:
print ("correct")
self.manager.home_switch() # use manager property
else:
print ("incorrect")
else:
print ("empty")

Navigation drawer is not hiding in kivymd while using nested screenmanagers

MDScreen:
MDNavigationLayout:
ScreenManager:
MDScreen:
MDBoxLayout:
orientation:'vertical'
MDToolbar:
title:"Teacher Section"
left_action_items:[["menu",lambda x:nav_drawer.set_state("open")]]
right_action_items:[["magnify",lambda x:None]]
elevation:5
MDScreen:
ScreenManager:
id:nestedsm
MDScreen:
name:"Screen1"
MDLabel:
text:"Screen1"
MDScreen:
name:"Screen2"
MDLabel:
text:"Screen2"
Widget:
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
orientation: 'vertical'
padding: "8dp"
spacing: "8dp"
Image:
id: avatar
size_hint: (1,1)
source: "images/kitten.png"
MDLabel:
text: "Bhushan Ghevde"
font_style: "Subtitle1"
size_hint_y: None
height: self.texture_size[1]
MDLabel:
text: "bhushanghevde15#gmail.com"
size_hint_y: None
font_style: "Caption"
height: self.texture_size[1]
ScrollView:
DrawerList:
id: md_list
MDList:
OneLineIconListItem:
text: "Add Teacher"
on_release:
nestedsm.current = 'Screen1'
IconLeftWidget:
icon: "face-profile"
OneLineIconListItem:
text: "Upload"
on_release:
nestedsm.current = 'Screen2'
IconLeftWidget:
icon: "upload"
I am creating a collage level app for manageing student details . The Normal Screenmanager works perfectly fine . while i was trying nested Screen manager i am facing problems . the problem is , when i try to change screen from navigation drawer , it changes screen but doesnt hide automatically , i have to click back again to hide. any help is appreciated . Thank you in advanced..
i have provided video of issue
Welcome, you can add the line:
root.ids.nav_drawer.set_state(new_state='toggle', animation=True)
Under the "on_release" of every list item, if you are adding those using the "for loop", you should add them like:
self.root.ids.content_drawer.ids.md_list.add_widget(OneLineIconListItem(icon=icon_name, text="Item number 1", on_release=lamda x:(self.root.ids.nav_drawer.set_state(new_state='toggle', animation=True))))
Or you can just implement it inside of the kivy lang:
Screen:
#MDNavigationLayout: #unknown class
ScreenManager:
Screen:
MDBoxLayout:
orientation:'vertical'
MDToolbar:
title:"Teacher Section"
left_action_items:[["menu",lambda x:nav_drawer.set_state("open")]]
right_action_items:[["magnify",lambda x:None]]
elevation:5
MDScreen:
ScreenManager:
id:nestedsm
MDScreen:
name:"Screen1"
MDLabel:
text:"Screen1"
MDScreen:
name:"Screen2"
MDLabel:
text:"Screen2 jbsidis"
Widget:
MDNavigationDrawer:
id: nav_drawer
BoxLayout:
orientation: 'vertical'
padding: "8dp"
spacing: "8dp"
Image:
id: avatar
size_hint: (1,1)
source: "images/pro.jpg" #"images/kitten.png"
MDLabel:
text: "Bhushan Ghevde"
font_style: "Subtitle1"
size_hint_y: None
height: self.texture_size[1]
MDLabel:
text: "bhushanghevde15#gmail.com"
size_hint_y: None
font_style: "Caption"
height: self.texture_size[1]
ScrollView:
MDList:
id: md_list
OneLineIconListItem:
text: "Add Teacher"
on_release:
nestedsm.current = 'Screen1'
root.ids.nav_drawer.set_state(new_state='toggle', animation=True)
IconLeftWidget:
icon: "face-profile"
OneLineIconListItem:
text: "Upload"
on_release:
nestedsm.current = 'Screen2'
root.ids.nav_drawer.set_state(new_state='toggle', animation=True)
IconLeftWidget:
icon: "upload"
Picture:

Blank White space overlapping KivyMD ImageList from MDToolbar

I am practicing KivyMD ImageList, and the imagelist is been overlayed by a blank space coming from MDBottomAppbar.
Here's what it looks like:
Please how do I remove the white blank space that is above MDBottomAppbar and overlapping Imagelist. Here's my code.. Thanks in Advance!
from kivymd.app import MDApp
from kivy.lang.builder import Builder
from kivy.core.window import Window
Window.size = (330, 500)
kv = '''
<MyTile#SmartTileWithLabel>
size_hint_y: None
height: "240dp"
BoxLayout:
orientation: "vertical"
md_bg_color: (240/255, 240/255, 240/255, 1)
MDToolbar:
id: success_screen_toolbar
title: "Project"
right_action_items: [["progress-check", lambda x: x]]
ScrollView:
size_hint_y: None
size: "280dp", "360dp"
pos_hint: {"center_x": .5, "center_y": .6}
height: root.height - success_screen_toolbar.height - dp(90)
y: root.height - success_screen_toolbar.height - dp(50)
elevation: 8
MDGridLayout:
cols: 1
adaptive_height: True
padding: dp(4), dp(4)
spacing: dp(4)
MyTile:
source: "C:/Users/HP USER/Downloads/bella_baron.jpg"
text: "[size=26]Cat 1[/size]\\n[size=14]cat-1.jpg[/size]"
MyTile:
source: "C:/Users/HP USER/Downloads/bella_baron.jpg"
text: "[size=26]Cat 2[/size]\\n[size=14]cat-2.jpg[/size]"
tile_text_color: app.theme_cls.accent_color
MyTile:
source: "C:/Users/HP USER/Downloads/bella_baron.jpg"
text: "[size=26][color=#ffffff]Cat 3[/color][/size]\\n[size=14]cat-3.jpg[/size]"
tile_text_color: app.theme_cls.accent_color
MDBottomAppBar:
MDToolbar:
id: success_screen_bottomappbar
icon: "magnify"
on_action_button: x
type: 'bottom'
mode: 'center'
elevation: '8dp'
left_action_items: [["calendar-text", lambda x: x], ["account-group", lambda x: x]]
right_action_items: [["magnify", lambda x: x], ["menu", lambda x: x]]
'''
class Main(MDApp):
def build(self):
return Builder.load_string(kv)
Main().run()
Use the following please, I have changed a few things and a few main widgets in your code because they added additional space that was not being used and that caused the white space in the body of the app, so here is the code by jbsidis:
from kivymd.app import MDApp
from kivy.lang.builder import Builder
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
Window.size = (330, 500)
kv = '''
#:import MDTextField kivymd.uix.textfield.MDTextField
<MyTile#SmartTileWithLabel>
size_hint_y: None
height: "240dp"
<S>:
MDTextFieldRound:
pos_hint: {"center_x": .5, "center_y": .95}
normal_color : [1,1,1,.1]
color_active : [1,1,1,1]
size_hint: .8, .07
hint_text : 'Search a product...'
icon_left : 'magnify'
Screen:
FloatLayout:
BoxLayout:
id: m5
pos_hint: {"center_x": .5, "center_y": .371} #this will change if you change this Window.size = (330, 500)
orientation: "vertical"
ScrollView:
MDGridLayout:
cols: 1
adaptive_height: True
padding: dp(4), dp(4)
spacing: dp(4)
MyTile:
source: "Photos/pro.jpg"
text: "[size=26]jbsidis[/size]\\n[size=14]cat-1.jpg[/size]"
MyTile:
source: "Photos/pro.jpg"
text: "[size=26]jbsidis[/size]\\n[size=14]cat-2.jpg[/size]"
tile_text_color: app.theme_cls.accent_color
MyTile:
source: "Photos/pro.jpg"
text: "[size=26][color=#ffffff]jbsidis[/color][/size]\\n[size=14]cat-3.jpg[/size]"
tile_text_color: app.theme_cls.accent_color
MyTile:
source: "a11.png"
text: ""
tile_text_color: [0,0,0,0]
FloatLayout:
AnchorLayout:
pos_hint: {"center_x": .5, "center_y": .9}
MDTextButton:
halign: "center"
text: "\\n\\n\\n\\n\\n\\n\\nLoading more...\\n\\n"
MDSpinner:
size_hint: .1,.1
MDToolbar:
id: success_screen_toolbar
title: "Project"
pos_hint: {"top": 1}
right_action_items: [["progress-check", lambda: print(6)]]
MDBottomAppBar:
MDToolbar:
id: success_screen_bottomappbar
icon: "magnify"
on_action_button: root.add_widget(app.sbar())
type: 'bottom'
mode: 'center'
#elevation: '8dp'
left_action_items: [["calendar-text", lambda: print(6)], ["account-group", lambda: print(6)]]
right_action_items: [["magnify", lambda: print(6)], ["menu", lambda: print(6)]]
'''
class blanks1(BoxLayout):
pass
class S(FloatLayout):
pass
class Main(MDApp):
def build(self):
return Builder.load_string(kv)
def sbar(self):
self.root.ids.success_screen_toolbar.md_bg_color=[1,1,1,1]
return S()
Main().run()
I also added the function to add the search bar on top when we press the magnified glass icon at the bottom bar, I added an empty image at the bottom of the pictures so you can show your app is loading more results, hope this is helpful for you and everybody, greetings from El Salvador, picture (something else, the a11.png image is a blank transparent png image, the last should be an empty image to extend the scroll area otherwise the bottom bar will hide it, this is something that most operating systems implement but we cannot know because we don't see the source code, watch my youtube channel: https://www.youtube.com/channel/UCIMmPyY7XjWHk1AHlR_UdWQ ):

Label not being displayed in kivy screen with Navigation drawer

Here I am trying to build a app having navigation bar.The navigation bar have OneLineListItem when I click those items the screen changes but label is not appearing.I also tried adding multiple buttons in the layout it works fine.But when I add Label it is not being displayed.
Following is the kv language code I used:-
#:import FadeTransition kivy.uix.screenmanager.FadeTransition
# Menu item in the DrawerList list.
<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: None
height: avatar.height
Image:
id: avatar
size_hint: None, None
size: "56dp", "56dp"
source: "data/logo/kivy-icon-256.png"
MDLabel:
text: "Voice Cloning Tool"
font_style: "Button"
size_hint_y: None
height: self.texture_size[1]
MDLabel:
text: "MENU"
font_style: "Caption"
size_hint_y: None
height: self.texture_size[1]
ScrollView:
DrawerList:
OneLineListItem:
text:'Home'
on_release:app.root.current='home_screen'
OneLineListItem:
text:'Record Voice'
on_release:app.root.current='rec_screen'
OneLineListItem:
text:'Help'
OneLineListItem:
text:'About'
OneLineListItem:
text:'Contact Us'
ScreenManagement:
transition:FadeTransition()
HomeScreen:
RecordScreen:
AboutScreen:
ContactUSScreen:
<HomeScreen>:
name:'home_screen'
NavigationLayout:
ScreenManager:
Screen:
SliderWin
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Explore Voice cloning Tool"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.toggle_nav_drawer()]]
Widget:
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
id: content_drawer
<RecordScreen>:
name:'rec_screen'
NavigationLayout:
ScreenManager:
Screen:
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Explore Voice cloning Tool"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.toggle_nav_drawer()]]
Button:
text:'Hello World'
size_hint:0.5,0.1
pos_hint:{'x':0.5,'y':0.5}
Button:
text:'Hello World'
size_hint:0.5,0.1
pos_hint:{'x':0.5,'y':0.5}
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
id: content_drawer
I was being idiot here.I forgot the fact that by default the label has white color.Here my background was white too that was the reason it was not being displayed.
I changed the color of the label to some other color and it displayed.Below is the changed code:-
#:import FadeTransition kivy.uix.screenmanager.FadeTransition
# Menu item in the DrawerList list.
<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: None
height: avatar.height
Image:
id: avatar
size_hint: None, None
size: "56dp", "56dp"
source: "data/logo/kivy-icon-256.png"
MDLabel:
text: "Voice Cloning Tool"
font_style: "Button"
size_hint_y: None
height: self.texture_size[1]
MDLabel:
text: "MENU"
font_style: "Caption"
size_hint_y: None
height: self.texture_size[1]
ScrollView:
DrawerList:
OneLineListItem:
text:'Home'
on_release:app.root.current='home_screen'
OneLineListItem:
text:'Record Voice'
on_release:app.root.current='rec_screen'
OneLineListItem:
text:'Help'
OneLineListItem:
text:'About'
OneLineListItem:
text:'Contact Us'
ScreenManagement:
transition:FadeTransition()
HomeScreen:
RecordScreen:
AboutScreen:
ContactUSScreen:
<HomeScreen>:
name:'home_screen'
NavigationLayout:
ScreenManager:
Screen:
SliderWin
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Explore Voice cloning Tool"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.toggle_nav_drawer()]]
Widget:
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
id: content_drawer
<RecordScreen>:
name:'rec_screen'
NavigationLayout:
ScreenManager:
Screen:
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Explore Voice cloning Tool"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.toggle_nav_drawer()]]
Label:
text:'Hello World'
size_hint:0.5,0.1
pos_hint:{'x':0.5,'y':0.5}
color:1,0,1,1
Button:
text:'Hello World'
size_hint:0.5,0.1
pos_hint:{'x':0.5,'y':0.5}
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
id: content_drawer

Resources