Related
Hiii,
I am a beginner in kivymd and python.
I am working on my new app and got stuck at this point.. where i want to add some widgets by using a function but it throws an error..
i don't know what's wrong with it ..
it gave me this error :
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/kivy/uix/gridlayout.py", line 307, in on_children raise GridLayoutException( kivy.uix.gridlayout.GridLayoutException: Too many children in GridLayout. Increase rows/cols!
i just want to add one widget but it saying "too many children in GridLayout"
i can't understand what it means
please explain me this.
import kivymd
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
from kivymd.uix.button import MDRaisedButton
from kivymd.uix.screenmanager import MDScreenManager
from kivymd.uix.screen import MDScreen
from kivymd.uix.relativelayout import MDRelativeLayout
from kivymd.uix.card import MDCard
from kivymd.uix.label import MDLabel
from kivy.core.text import LabelBase
kv = '''
bseb_layout:
screen_mngr: screen_mngr
MDScreenManager:
id: screen_mngr
subjects: subjects
chapter_list: chapter_list
#======================================================
#===================subjects===========================
MDScreen:
id: subjects
name: "subjects"
MDLabel:
text: "Question Bank\\n10 Years"
font_size: "30dp"
pos_hint: {"x": 0.1, "y": 0.42}
MDLabel:
text: "Chapter-wise"
font_size: "20dp"
pos_hint: {"x": 0.1, "y": 0.35}
MDCard:
size_hint: 0.45,0.4
pos_hint: {"x":0.025, "y": 0.4}
md_bg_color: 1,0,1,0.2
radius: 25,25,25,25
on_press: app.func()
on_press: root.screen_mngr.current = "chapter_list"
MDRelativeLayout:
MDLabel:
text: "Physics"
font_size: "25dp"
pos_hint: {"x": 0.2, "y": 0}
MDCard:
size_hint: 0.45,0.3
pos_hint: {"x":0.525, "y": 0.5}
md_bg_color: 1,0,1,0.2
radius: 25,25,25,25
on_press: print('Works')
MDRelativeLayout:
MDLabel:
text: "chemistry"
font_size: "25dp"
pos_hint: {"x": 0.2, "y": 0}
MDCard:
size_hint: 0.45,0.3
pos_hint: {"x":0.025, "y": 0.05}
md_bg_color: 1,0,1,0.2
radius: 25,25,25,25
on_press: print('Works')
MDRelativeLayout:
MDLabel:
text: "English"
font_size: "25dp"
pos_hint: {"x": 0.2, "y": 0}
MDCard:
size_hint: 0.45,0.4
pos_hint: {"x":0.525, "y": 0.05}
md_bg_color: 1,0,1,0.2
radius: 25,25,25,25
on_press: print('Works')
MDRelativeLayout:
MDLabel:
text: "Biology"
font_size: "25dp"
pos_hint: {"x": 0.2, "y": 0}
#===================subjects-END=======================
#=================chapter_list=========================
MDScreen:
id: chapter_list
name: "chapter_list"
chapter_grid: chapter_grid
FitImage:
source: "grad3.jpg"
MDLabel:
text: "Phsycis\\nChapters"
font_size: "30dp"
pos_hint: {"x": 0.1, "y": 0.42}
MDScrollView:
id: location
md_bg_color: 1,1,1,0.1
size_hint: 0.95,0.03
pos_hint: {"center_x":0.5,"y": 0.83}
do_scroll_x: True
do_scroll_y: False
radius: 25,25,25,25
bar_color: 214/255, 99/255, 168/255,0.5
bar_inactive_color: 1,1,1,0
MDGridLayout:
id: chapter_grid
adaptive_height: True
adaptive_width: True
cols: 1
rows:1
padding: ("20dp","0dp")
MDCard:
size_hint: None,None
size: "350dp","15dp"
md_bg_color: 1,0,1,0.2
MDRelativeLayout:
MDLabel:
text: "Physics > 2023 > Chapters"
font_size: "15dp"
pos_hint: {"x": 0.0, "center_y": 0.5}
MDScrollView:
md_bg_color: 1,1,1,0.2
size_hint: 0.95,0.8
pos_hint: {"center_x":0.5,"y": 0.02}
do_scroll_x: False
radius: 25,25,25,25
bar_color: 214/255, 99/255, 168/255,0.5
bar_inactive_color: 1,1,1,0
MDGridLayout:
adaptive_height: True
adaptive_width: True
cols: 1
padding: ("11dp","10dp")
spacing: "10dp"
MDCard:
size_hint: None,None
size: "320dp", "60dp"
md_bg_color: 1,0,1,0.2
radius: 25,25,25,25
on_press: print('Works')
MDRelativeLayout:
MDLabel:
text: "Electrostatics"
font_size: "20dp"
pos_hint: {"x": 0.1, "center_y": 0.5}
#==================chapter_list-END====================
'''
class bseb_layout(FloatLayout):
pass
class bseb(MDApp):
def func(self):
self.root.ids.screen_mngr.chapter_list.chapter_grid.add_widget(
MDCard(
MDRelativeLayout(
MDLabel(
text="chapter_2",
font_size="20dp",
theme_text_color="Custom",
text_color=(1,1,1,1),
pos_hint={"x":0.1,"center_y":0.5}
)
),
size_hint=(None,None),
size=("320dp","60dp"),
md_bg_color=(1,1,1,0.2),
radius=(25,25,25,25),
)
)
def build(self):
return Builder.load_string(kv)
if __name__=="__main__":
bseb().run()
Any help is much appreciated...
Thank you.
Your code:
MDGridLayout:
id: chapter_grid
adaptive_height: True
adaptive_width: True
cols: 1
rows:1
Limits that MDGridLayout to exactly one column and one row. That means that it can only have one child widget. If you want to allow more than one row, then remove the rows: 1, or, if you want more than one column, remove the cols: 1. But you cannot remove both. You must specify one of rows: or cols:.
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")
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:
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.
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