Kivy: Multiple Screens and Menu Items not impletmenting - python

I am very new in kivy and working on a simple application using python. I want to create an application in kivy which comprises of constant menu items on left pane and their respective screens on right big pane or screen. But I am unable to find the solution in kivy examples and also in youtube video tutorials and also in google. Please check my simple code and refer to some solution.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.base import runTouchApp
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
from kivy.properties import NumericProperty
#Code Starts here
Builder.load_string("""
#:import random random.random
#:import NoTransition kivy.uix.screenmanager.NoTransition
<MenuScreen>:
hue: random()
canvas:
Color:
hsv: self.hue, .5, .12
Rectangle:
size: self.size
Button:
text: 'Home'
size_hint: None, None
pos_hint: {'center_x':0.05, 'center_y':0.95}
size: 150, 50
on_release: root.manager.current = 'home'
on_release: root.manager.transition = NoTransition(duration=0)
Button:
text: 'Login History'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.88}
size: 150, 50
on_release: root.manager.current = 'loginhistory'
on_release: root.manager.transition = NoTransition(duration=0)
Button:
text: 'Alarm History'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.81}
size: 150, 50
on_release: root.manager.current = 'alarmhistory'
on_release: root.manager.transition = NoTransition(duration=0)
Button:
text: 'User Management'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.74}
size: 150, 50
on_release: root.manager.current = 'usermanagement'
on_release: root.manager.transition = NoTransition(duration=0)
Button:
text: 'Call SoS'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.67}
size: 150, 50
on_release: root.manager.current = 'callsos'
on_release: root.manager.transition = NoTransition(duration=0)
Button:
text: 'Settings'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.60}
size: 150, 50
on_release: root.manager.current = 'settings'
on_release: root.manager.transition = NoTransition(duration=0)
Button:
text: 'Call RealTec'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.53}
size: 150, 50
on_release: root.manager.current = 'callrealtec'
on_release: root.manager.transition = NoTransition(duration=0)
BoxLayout:
size_hint: .5, None
height: 250
pos_hint: {'center_x': .5}
orientation: 'vertical'
<HomeScreen>:
hue: random()
canvas:
Color:
hsv: self.hue, .5, .2
Rectangle:
size: self.size
Button:
background_color: [1, 2, 1, 2]
text: 'Home'
size_hint: None, None
pos_hint: {'center_x':0.05, 'center_y':0.95}
size: 150, 50
Button:
text: 'Login History'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.88}
size: 150, 50
on_release: root.manager.current = 'loginhistory'
Button:
text: 'Alarm History'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.81}
size: 150, 50
on_release: root.manager.current = 'alarmhistory'
Button:
text: 'User Management'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.74}
size: 150, 50
on_release: root.manager.current = 'usermanagement'
Button:
text: 'Call SoS'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.67}
size: 150, 50
on_release: root.manager.current = 'callsos'
Button:
text: 'Settings'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.60}
size: 150, 50
on_release: root.manager.current = 'settings'
Button:
text: 'Call RealTec'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.53}
size: 150, 50
on_release: root.manager.current = 'callrealtec'
Button:
text: 'Main Menu'
size_hint: None, None
pos_hint: {'center_x':0.05, 'center_y':0.46}
size: 150, 50
on_release: root.manager.current = 'menu'
BoxLayout:
size_hint: .5, None
height: 250
pos_hint: {'center_x': .5}
orientation: 'vertical'
<LoginHistoryScreen>:
hue: random()
canvas:
Color:
hsv: self.hue, .5, .9
Rectangle:
size: self.size
Button:
text: 'Home'
size_hint: None, None
pos_hint: {'center_x':0.05, 'center_y':0.95}
size: 150, 50
on_release: root.manager.current = 'home'
Button:
text: 'Login History'
background_color: [1, 2, 1, 2]
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.88}
size: 150, 50
Button:
text: 'Alarm History'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.81}
size: 150, 50
on_release: root.manager.current = 'alarmhistory'
Button:
text: 'User Management'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.74}
size: 150, 50
on_release: root.manager.current = 'usermanagement'
Button:
text: 'Call SoS'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.67}
size: 150, 50
on_release: root.manager.current = 'callsos'
Button:
text: 'Settings'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.60}
size: 150, 50
on_release: root.manager.current = 'settings'
Button:
text: 'Call RealTec'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.53}
size: 150, 50
on_release: root.manager.current = 'callrealtec'
Button:
text: 'Main Menu'
size_hint: None, None
pos_hint: {'center_x':0.05, 'center_y':0.46}
size: 150, 50
on_release: root.manager.current = 'menu'
BoxLayout:
size_hint: .5, None
height: 250
pos_hint: {'center_x': .5}
orientation: 'vertical'
<AlarmHistoryScreen>:
hue: random()
canvas:
Color:
hsv: self.hue, .5, .6
Rectangle:
size: self.size
Button:
text: 'Home'
size_hint: None, None
pos_hint: {'center_x':0.05, 'center_y':0.95}
size: 150, 50
on_release: root.manager.current = 'home'
Button:
text: 'Login History'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.88}
size: 150, 50
on_release: root.manager.current = 'loginhistory'
Button:
text: 'Alarm History'
background_color: [1, 2, 1, 2]
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.81}
size: 150, 50
Button:
text: 'User Management'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.74}
size: 150, 50
on_release: root.manager.current = 'usermanagement'
Button:
text: 'Call SoS'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.67}
size: 150, 50
on_release: root.manager.current = 'callsos'
Button:
text: 'Settings'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.60}
size: 150, 50
on_release: root.manager.current = 'settings'
Button:
text: 'Call RealTec'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.53}
size: 150, 50
on_release: root.manager.current = 'callrealtec'
Button:
text: 'Main Menu'
size_hint: None, None
pos_hint: {'center_x':0.05, 'center_y':0.46}
size: 150, 50
on_release: root.manager.current = 'menu'
BoxLayout:
size_hint: .5, None
height: 250
pos_hint: {'center_x': .5}
orientation: 'vertical'
<UserManagementScreen>:
hue: random()
canvas:
Color:
hsv: self.hue, .5, .8
Rectangle:
size: self.size
Button:
text: 'Home'
size_hint: None, None
pos_hint: {'center_x':0.05, 'center_y':0.95}
size: 150, 50
on_release: root.manager.current = 'home'
Button:
text: 'Login History'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.88}
size: 150, 50
on_release: root.manager.current = 'loginhistory'
Button:
text: 'Alarm History'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.81}
size: 150, 50
on_release: root.manager.current = 'alarmhistory'
Button:
text: 'User Management'
background_color: [1, 2, 1, 2]
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.74}
size: 150, 50
Button:
text: 'Call SoS'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.67}
size: 150, 50
on_release: root.manager.current = 'callsos'
Button:
text: 'Settings'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.60}
size: 150, 50
on_release: root.manager.current = 'settings'
Button:
text: 'Call RealTec'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.53}
size: 150, 50
on_release: root.manager.current = 'callrealtec'
Button:
text: 'Main Menu'
size_hint: None, None
pos_hint: {'center_x':0.05, 'center_y':0.46}
size: 150, 50
on_release: root.manager.current = 'menu'
BoxLayout:
size_hint: .5, None
height: 250
pos_hint: {'center_x': .5}
orientation: 'vertical'
<CallSoSScreen>:
hue: random()
canvas:
Color:
hsv: self.hue, .5, .7
Rectangle:
size: self.size
Button:
text: 'Home'
size_hint: None, None
pos_hint: {'center_x':0.05, 'center_y':0.95}
size: 150, 50
on_release: root.manager.current = 'home'
Button:
text: 'Login History'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.88}
size: 150, 50
on_release: root.manager.current = 'loginhistory'
Button:
text: 'Alarm History'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.81}
size: 150, 50
on_release: root.manager.current = 'alarmhistory'
Button:
text: 'User Management'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.74}
size: 150, 50
on_release: root.manager.current = 'usermanagement'
Button:
text: 'Call SoS'
background_color: [1, 2, 1, 2]
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.67}
size: 150, 50
Button:
text: 'Settings'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.60}
size: 150, 50
on_release: root.manager.current = 'settings'
Button:
text: 'Call RealTec'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.53}
size: 150, 50
on_release: root.manager.current = 'callrealtec'
Button:
text: 'Main Menu'
size_hint: None, None
pos_hint: {'center_x':0.05, 'center_y':0.46}
size: 150, 50
on_release: root.manager.current = 'menu'
BoxLayout:
size_hint: .5, None
height: 250
pos_hint: {'center_x': .5}
orientation: 'vertical'
<SettingsScreen>:
hue: random()
canvas:
Color:
hsv: self.hue, .5, .5
Rectangle:
size: self.size
Button:
text: 'Home'
size_hint: None, None
pos_hint: {'center_x':0.05, 'center_y':0.95}
size: 150, 50
on_release: root.manager.current = 'home'
Button:
text: 'Login History'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.88}
size: 150, 50
on_release: root.manager.current = 'loginhistory'
Button:
text: 'Alarm History'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.81}
size: 150, 50
on_release: root.manager.current = 'alarmhistory'
Button:
text: 'User Management'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.74}
size: 150, 50
on_release: root.manager.current = 'usermanagement'
Button:
text: 'Call SoS'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.67}
size: 150, 50
on_release: root.manager.current = 'callsos'
Button:
text: 'Settings'
background_color: [1, 2, 1, 2]
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.60}
size: 150, 50
Button:
text: 'Call RealTec'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.53}
size: 150, 50
on_release: root.manager.current = 'callrealtec'
Button:
text: 'Main Menu'
size_hint: None, None
pos_hint: {'center_x':0.05, 'center_y':0.46}
size: 150, 50
on_release: root.manager.current = 'menu'
BoxLayout:
size_hint: .5, None
height: 250
pos_hint: {'center_x': .5}
orientation: 'vertical'
<CallRealTecScreen>:
hue: random()
canvas:
Color:
hsv: self.hue, .5, .4
Rectangle:
size: self.size
Button:
text: 'Home'
size_hint: None, None
pos_hint: {'center_x':0.05, 'center_y':0.95}
size: 150, 50
on_release: root.manager.current = 'home'
Button:
text: 'Login History'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.88}
size: 150, 50
on_release: root.manager.current = 'loginhistory'
Button:
text: 'Alarm History'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.81}
size: 150, 50
on_release: root.manager.current = 'alarmhistory'
Button:
text: 'User Management'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.74}
size: 150, 50
on_release: root.manager.current = 'usermanagement'
Button:
text: 'Call SoS'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.67}
size: 150, 50
on_release: root.manager.current = 'callsos'
Button:
text: 'Settings'
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.60}
size: 150, 50
on_release: root.manager.current = 'settings'
Button:
text: 'Call RealTec'
background_color: [1, 2, 1, 2]
size_hint: None, None
pos_hint: {'center_x':.05, 'center_y':.53}
size: 150, 50
Button:
text: 'Main Menu'
size_hint: None, None
pos_hint: {'center_x':0.05, 'center_y':0.46}
size: 150, 50
on_release: root.manager.current = 'menu'
BoxLayout:
size_hint: .5, None
height: 250
pos_hint: {'center_x': .5}
orientation: 'vertical'
""")
# Declare both screens
class MenuScreen(Screen):
hue = NumericProperty(0)
pass
class HomeScreen(Screen):
hue = NumericProperty(0)
pass
class LoginHistoryScreen(Screen):
hue = NumericProperty(0)
pass
class AlarmHistoryScreen(Screen):
hue = NumericProperty(0)
pass
class UserManagementScreen(Screen):
hue = NumericProperty(0)
pass
class CallSosScreen(Screen):
hue = NumericProperty(0)
pass
class SettingsScreen(Screen):
hue = NumericProperty(0)
pass
class CallRealTecScreen(Screen):
hue = NumericProperty(0)
pass
sm = ScreenManager()
sm.add_widget(MenuScreen(name='menu'))
sm.add_widget(HomeScreen(name='home'))
sm.add_widget(LoginHistoryScreen(name='loginhistory'))
sm.add_widget(AlarmHistoryScreen(name='alarmhistory'))
sm.add_widget(UserManagementScreen(name='usermanagement'))
sm.add_widget(CallSosScreen(name='callsos'))
sm.add_widget(CallRealTecScreen(name='callrealtec'))
sm.add_widget(SettingsScreen(name='settings'))
class TestApp(App):
def build(self):
return sm
if __name__ == '__main__':
TestApp().run()

I didn't read through your code. You should be providing a Minimal, Complete, and Verifiable example. That said here's a short example that you can build upon. The main take away from the example, is that you don't have to add ScreenManager as a top level widget.
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
class Manager(ScreenManager):
def __init__(self, *args, **kwargs):
super(Manager, self).__init__(*args, **kwargs)
for i in range(4):
txt = 'Screen {}'.format(i)
lbl = Label(text=txt)
screen = Screen(name=txt)
screen.add_widget(lbl)
self.add_widget(screen)
class Nav(GridLayout):
def __init__(self, sm=None, *args, **kwargs):
super(Nav, self).__init__(*args, **kwargs)
self.sm = sm
self.rows = 4
self.size_hint = (.2, 1)
for i in range(4):
self.add_widget(Button(text="Screen {}".format(i), on_release=self.change))
def change(self, btn):
self.sm.current = btn.text
class Root(BoxLayout):
def __init__(self, *args, **kwargs):
super(Root, self).__init__(*args, **kwargs)
self.orientation = "horizontal"
sm = Manager()
self.add_widget(Nav(sm=sm))
self.add_widget(sm)
class TestApp(App):
def build(App):
return Root()
if __name__ == '__main__':
TestApp().run()

Related

KivyMD Text Field doesn't work, recieve attribute error when pressing clear button and MD Cards arent aligned properly

I completed my code for main window which is the login page and I'm writing my code for the second page. Then, I tried to use the text field on my login screen and I can't type in it. However, before making my second window, the text field worked as expected and I can type in it. What could cause this issue?
Furthermore, I recieve an error (AttributeError: 'super' object has no attribute 'getattr'
) when I tried to press the clear button in main window.
Also, if you tried to run this code and see the second window, you will notice 3 MD cards not aligned properly if you don't expand the window to full size. if you have any idea how to fix it, please let me know.
SUMMARY OF WHAT I'M TRYING TO ACHIEVE HERE:
Figure out what why I can't use the textfield in main window
Fix the error when press the clear button
Align MD Cards properly
.py file
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.screenmanager import ScreenManager, Screen
class MainWindow(Screen):
pass
class SecondWindow(Screen):
pass
class WindowManager(ScreenManager):
pass
class BaseApp(MDApp):
def build(self):
self.theme_cls.theme_style = "Light"
self.theme_cls.primary_palette = "Green"
return Builder.load_file("base.kv")
def clear(self):
self.root.ids.user.text = ""
self.root.ids.passw.text = ""
if __name__ == "__main__":
BaseApp().run()```
.kv file
# Filename: base.kv
#:kivy 2.1.0
#:include main.py
WindowManager:
MainWindow:
SecondWindow:
<MainWindow>:
name: "main"
Screen:
MDCard:
size_hint: None, None
size: 400, 500
pos_hint: {"center_x": 0.5, "center_y": 0.5}
elevation: 10
padding: 25
spacing: 25
orientation: "vertical"
MDLabel:
id: login_label
text: "WELCOME TO JAMES MADISON/n HIGH SCHOOL STUDENTS APP"
font_size: 22
font_name: "Raleway-Regular"
halign: "center"
size_hint_y: None
height: self.texture_size[1]
padding_y: 15
MDBoxLayout:
Image:
source: "jmhs.png"
size_hint_x: 1.15
halign: "center"
size_hint_y: 1.15
height: self.texture_size[1]
padding_y: 10
MDTextFieldRound:
id: user
hint_text: "Username"
icon_right: "account"
size_hint_x: None
width: 200
font_size: 18
font_name: "Roboto-Regular"
pos_hint: {"center_x": 0.5}
MDTextFieldRound:
id: passw
hint_text: "Password"
icon_right: "eye-off"
size_hint_x: None
width: 200
font_size: 18
font_name: "Roboto-Regular"
pos_hint: {"center_x": 0.5}
password: True
MDRoundFlatButton:
text: "LOG IN"
font_size: 12
font_name: "Raleway-Regular"
pos_hint: {"center_x": 0.5}
on_press:
app.root.current = "second"
root.manager.transition.direction = "left"
MDRoundFlatButton:
text: "CLEAR"
font_size: 12
font_name: "Raleway-Regular"
pos_hint: {"center_x": 0.5}
on_press: app.clear()
<SecondWindow>:
name: "second"
MDBoxLayout:
orientation: "horizontal"
MDBoxLayout:
size_hint: .225, 1
canvas.before:
Color:
rgba: 0, 0, 0, 0
Rectangle:
pos: self.pos
size: self.size
MDBoxLayout:
orientation: "vertical"
spacing: "10dp"
size_hint: 1, 1
canvas.before:
Color:
rgba: 227/255, 255/255, 226/255, 0.8
Rectangle:
pos: self.pos
size: self.size
MDBoxLayout:
spacing: "10dp"
size_hint: 1, .1
MDBoxLayout:
spacing: "10dp"
size_hint: 1, .9
canvas.before:
Color:
rgba: 227/255, 255/255, 226/255, 0.8
Rectangle:
pos: self.pos
size: self.size
MDGridLayout:
cols: 3
padding: 18
spacing: "20dp"
MDCard:
padding: 16
elevation: 0
border_radius: 20
radius: [15]
size_hint: None, None
size: "370dp", "140dp"
pos_hint: {"center_x": .5, "center_y": .5}
MDCard:
padding: 16
elevation: 0
border_radius: 20
radius: [15]
size_hint: None, None
size: "370dp", "140dp"
pos_hint: {"center_x": .5, "center_y": .5}
MDCard:
padding: 16
elevation: 0
border_radius: 20
radius: [15]
size_hint: None, None
size: "200dp", "140dp"
pos_hint: {"center_x": .5, "center_y": .5}
MDBoxLayout:
size_hint: .29, 1
canvas.before:
Color:
rgba: 0, 0, 0, 0
Rectangle:
pos: self.pos
size: self.size

Gridlayout height based on Label height in recycleview not aligned

I have managed to get the size of a box layout to change based on the corresponding Label height, however, it doesn't line up perfectly and I cannot figure out why.
I have looked at adding offsets but have had no luck since it ended up making the issue worse
Thank you for any help
MainInterface:
<MainInterface#BoxLayout>:
orientation: "vertical"
Label:
#font_name: "Nunito-Black.ttf"
text: "T R U T H"
size_hint: 1, 0.1
GridLayout:
size_hint: 1, 0.12
cols: 4
Button:
text: "Menu1"
Button:
text: "Menu2"
Button:
text: "Menu3"
Button:
text: "Menu4"
PageLayout:
border: "20dp"
swipe_threshold: 0.2
RecycleView:
viewclass: 'PostGrid'
scroll_y: 1
id: rv
data: app.posts
RecycleBoxLayout:
id: box
default_size: None, None
default_size_hint: 1, None
size_hint_y: None
padding: ["10dp", "16dp"]
spacing: "8dp"
height: self.minimum_height
orientation: 'vertical'
key_size: '_size'
BoxLayout:
orientation: "vertical"
Button:
text: "peni"
Button:
text: "tag # will J"
Button:
text: "Input"
<PostGrid#BoxLayout>:
message_id: -1
orientation: "horizontal"
text: ''
spacing: "10dp"
#size_hint: self.width, None
_size: 0, 74
size: 0, 74
text_size: None, None
BoxLayout:
orientation: "vertical"
spacing: "10dp"
size_hint: .1, 1
size: self.size
Button:
text: "UP"
font_size: "5dp"
size_hint: 1, 0.2
Button:
text: "DOWN"
font_size: "5dp"
size_hint: 1, 0.2
Label:
text: "test"
font_size: "5dp"
size_hint: 1, 0.6
Label:
text: root.text
padding: 5, 5
size_hint: .9, 1
#size: self.texture_size
height: self.texture_size[1]
text_size: self.width, None
color: 0,0,0,1
#text_size: self.width, None
#size_hint: None, 1
#size: self.texture_size
#font_name: "Nunito-Bold.ttf"
#font_size: "12dp"
multiline: True
#size: 1, root.min_height
on_texture_size:
app.update_message_size(
root.message_id,
self.texture_size,
root.width)
pos: self.pos
canvas.before:
Color:
rgba: (0.8, 0.8, 0.8, 1)
RoundedRectangle:
size: self.texture_size
radius: [5, 5, 5, 5]
pos: self.x, self.y
canvas:
Color:
rgba:0,0.9,0.9,1
Line:
width:0.8
rounded_rectangle:(self.x,self.y,self.width,self.height, 5)
from kivy.app import App
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.properties import ListProperty
from kivy.animation import Animation
from kivy.metrics import dp
class TruthApp(App):
posts = ListProperty([{'message_id':0, 'text':"testskjhfjksdhfkjshfjshfjkhskjdfhskjdhfkjshfdkjhsjkdfhskjhdfkjshdfjkhzxczxczxczxcxzczxcxsjkdfhjksdhfkjshkjdfhksjdhfjkshdfjkhsdkjhfkjshdfjkshkjfhskjhfkjshfjkshdkjfhskjhfjshfkjshdfjkshdjkfhskjhfkjshfjksdhjfhsjkdhfjkhsdkjfhskjhfjk\ngdgdgd\ndgdgdg\ndgdgdg\ndggdgd",'_size':[0,0] }, {'message_id':1, 'text':"testskjhfjksdhfkjshfjshfjkhskjdfhskjdhfkjshfdkjhsjkdfhskjhjfhskjhfjk,'_size':[0,0]"}])
def update_message_size(self, message_id, texture_size, max_width):
#print(self.posts)
#print("Here")
self.posts[message_id] = {**self.posts[message_id], '_size':[0, texture_size[1]]}
if __name__ == '__main__':
TruthApp().run()
^ Image showing how the code above runs
The problem is in the viewclass of RecycleView (i.e. PostGrid). You set its heightas such it could not accomodate its children which is supposed to be the minimum height that will place all its children.
Now that's exactly the attr. minimum_height does. With this being applied you also don't need default_size: None, None (especially the height attr.)
With this and other modifications your .kv file should now look like,
MainInterface:
<MainInterface#BoxLayout>:
orientation: "vertical"
Label:
#font_name: "Nunito-Black.ttf"
text: "T R U T H"
size_hint: 1, 0.1
GridLayout:
size_hint: 1, 0.12
cols: 4
Button:
text: "Menu1"
Button:
text: "Menu2"
Button:
text: "Menu3"
Button:
text: "Menu4"
PageLayout:
border: "20dp"
swipe_threshold: 0.2
RecycleView:
viewclass: 'PostGrid'
scroll_y: 1
id: rv
data: app.posts
RecycleBoxLayout:
id: box
default_size_hint: 1, None
size_hint_y: None
padding: ["10dp", "16dp"]
spacing: "8dp"
height: self.minimum_height
orientation: 'vertical'
key_size: '_size'
BoxLayout:
orientation: "vertical"
Button:
text: "peni"
Button:
text: "tag # will J"
Button:
text: "Input"
<PostGrid#BoxLayout>:
message_id: -1
orientation: "horizontal"
text: ''
spacing: "10dp"
size_hint_y: None
#_size: 0, 74
height: self.minimum_height
text_size: None, None
BoxLayout:
orientation: "vertical"
spacing: "10dp"
size_hint: .1, 1
Button:
text: "UP"
font_size: "5dp"
size_hint: 1, 0.2
Button:
text: "DOWN"
font_size: "5dp"
size_hint: 1, 0.2
Label:
text: "test"
font_size: "5dp"
size_hint: 1, 0.6
Label:
text: root.text
padding: 5, 5
#size_hint: .9, 1
#size: self.texture_size
size_hint_y: None
height: self.texture_size[1]
text_size: self.width, None
color: 0,0,0,1
#text_size: self.width, None
#size_hint: None, 1
#size: self.texture_size
#font_name: "Nunito-Bold.ttf"
#font_size: "12dp"
multiline: True
#size: 1, root.min_height
on_texture_size:
app.update_message_size(
root.message_id,
self.texture_size,
root.width)
pos: self.pos
canvas.before:
Color:
rgba: (0.8, 0.8, 0.8, 1)
RoundedRectangle:
size: self.texture_size
radius: [5, 5, 5, 5]
pos: self.x, self.y
canvas:
Color:
rgba:0,0.9,0.9,1
Line:
width:0.8
rounded_rectangle:(self.x,self.y,self.width,self.height, 5)

kivy VideoPlayer: Video does not return to its original size after full screen mode

When I double click on the video, it goes full screen, but if I double click on it again, it doesn't go back to normal. However, the rest of the window elements are partially visible. The part of my .kv code responsible for the VideoPlayer is given below:
<VideosWindow>:
name: 'vids'
FloatLayout:
FileChooserListView:
id:chooser
path: root.get_files_list()
canvas.before:
Color:
rgb: .4, .5, .5
Rectangle:
pos: self.pos
size: self.size
on_selection: root.select(chooser.selection)
size_hint: (.9, .15)
pos_hint: {'x':.05, 'y':.8}
VideoPlayer:
id:vid
options: {'eos':'loop'}
size_hint: (.9, .7)
pos_hint: {'x':.05, 'y':.05}
Button:
size_hint_y: 0.3
height: 48
text: "open"
disabled: not chooser.selection
on_release: root.select(chooser.selection)
size_hint: (.45, .05)
pos_hint: {'x':.05, 'y':.00}
Button:
text: 'Go Back'
color: (1,1,1,1)
background_normal:''
background_color: (0.3,0.6,0.7,1)
on_release:
vid.state = 'pause'
app.root.current = 'saved_files'
size_hint: (.45, .05)
pos_hint: {'x':.50, 'y':.00}
VideosWindow class code:
class VideosWindow(Screen):
def get_files_list(self):
files = os.sep.join([my_folder,'mp4'])
return files
def select(self, filename):
self.ids.vid.source = filename[0]
self.ids.vid.state = 'play'
The screenshots of my program before and after I go fullscreen mode:
before
after
Solved this issue by adding VideoPlayer widget to the GridLayout. Now .kv code looks like this:
<VideosWindow>:
name: 'vids'
FloatLayout:
FileChooserListView:
id:chooser
path: root.get_files_list()
canvas.before:
Color:
rgb: .4, .5, .5
Rectangle:
pos: self.pos
size: self.size
on_selection: root.select(chooser.selection)
size_hint: (.9, .15)
pos_hint: {'x':.05, 'y':.8}
GridLayout:
cols:1
size_hint: (.9, .7)
pos_hint: {'x':.05, 'y':.05}
VideoPlayer:
id:vid
options: {'eos':'loop'}
Button:
size_hint_y: 0.3
height: 48
text: "open"
disabled: not chooser.selection
on_release: root.select(chooser.selection)
size_hint: (.45, .05)
pos_hint: {'x':.05, 'y':.00}
Button:
text: 'Go Back'
color: (1,1,1,1)
background_normal:''
background_color: (0.3,0.6,0.7,1)
on_release:
vid.state = 'pause'
app.root.current = 'saved_files'
size_hint: (.45, .05)
pos_hint: {'x':.50, 'y':.00}
Don't know if it is good decision but it works.

kivy multiple instances of a screen with unique data

good day
is it possible to have multiple instances of a screen each using unique data? for example, i have a 'homescreen' with various buttons for various categories that takes you to a batch list screen unique to that category where you can add batches to be listed. each buttons batch list screen would have unique data to that category but the template for all batch list screens are the same.
ive made a simple example for one category but in order to expand it to the others would i need to repeat the code and create appropriately named .kv files and add each screen to the screen manager.
.py
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
from kivy.uix.behaviors.touchripple import TouchRippleButtonBehavior
from kivy.uix.button import Button
from kivy.clock import Clock
from kivy.uix.textinput import TextInput
class CapitalInput(TextInput):
def insert_text(self, substring, from_undo=False):
s = substring.upper()
return super(CapitalInput, self).insert_text(s, from_undo=from_undo)
class RippleButton(TouchRippleButtonBehavior, Button):
def on_touch_down(self, touch):
collide_point = self.collide_point(touch.x, touch.y)
if collide_point:
touch.grab(self)
self.transparency = self.background_color[3]
self.background_color[3] = 0.5 # set transparency to half (0.5)
self.ripple_show(touch)
self.dispatch('on_press')
return True
return False
def on_touch_up(self, touch):
if touch.grab_current is self:
touch.ungrab(self)
self.ripple_fade()
def defer_release(dt):
self.background_color[3] = self.transparency
self.dispatch('on_release')
Clock.schedule_once(defer_release, self.ripple_duration_out)
return True
return False
class AddBatchScreen(Screen):
pass
class BatchScreen(Screen):
pass
class HomeScreen(Screen):
pass
gui = Builder.load_file('BatchTracker.kv')
class BatchTrackerApp(App):
def build(self):
return gui
def insert(self, value):
bs = self.root.get_screen('batch_screen')
bs.ids.rv.data.insert(0, {'value': value or 'default value'})
if __name__ == '__main__':
BatchTrackerApp().run()
BatchTraker.kv
#:kivy 1.11.1
#:include batchscreen.kv
#:include add_batch_screen.kv
#:include homescreen.kv
#:import hex kivy.utils.get_color_from_hex
#:import TouchRippleButtonBehavior kivy.uix.behaviors.touchripple
#:import SlideTransition kivy.uix.screenmanager.SlideTransition
ScreenManager:
id: screen_manager
HomeScreen:
name: 'home_screen'
id: home_screen
BatchScreen:
name: 'batch_screen'
id: batch_screen
AddBatchScreen:
name: 'add_batch_screen'
id: add_batch_screen
<RoundButton#RippleButton>:
background_color: (0,0,0,0)
background_normal: ''
back_color: (1,0,1,1)
border_radius: [20]
canvas.before:
Color:
rgba: self.back_color
RoundedRectangle:
size: self.size
pos: self.pos
radius: self.border_radius
homescreen.kv
<HomeScreen>:
BoxLayout:
orientation: 'vertical'
canvas:
Color:
rgba: 0.5, 0.5, 0.5, 1
Rectangle:
size: self.size
pos: self.pos
Label:
canvas.before:
Color:
rgba: 1, 0.7, 0.5, 1
Rectangle:
size: self.size
pos: self.pos
size_hint_y: None
pos_hint: {'top': .1}
text: 'Home Screen'
font_size: 40
GridLayout:
rows: 4
AnchorLayout:
canvas:
Color:
rgba: 0.1, 0.1, 1, 0.9
Rectangle:
pos: self.pos
size: self.size
Button:
pos_hint: {'center_x': 0.5}
size_hint: 0.5, 0.7
halign: 'center'
valign: 'middle'
text: 'Isolations'
font_size: 40
size: self.texture_size
text_size: self.width, None
on_press: print('isolations')
on_release: root.manager.current = 'batch_screen'
AnchorLayout:
canvas:
Color:
rgba: 0.1, 0.1, 1, 0.9
Rectangle:
pos: self.pos
size: self.size
Button:
pos_hint: {'center_x': 0.5}
size_hint: 0.5, 0.7
halign: 'center'
valign: 'middle'
text: 'QPCR'
font_size: 40
size: self.texture_size
text_size: self.width, None
on_release: root.manager.current = 'batch_screen'
AnchorLayout:
canvas:
Color:
rgba: 0.1, 0.1, 1, 0.9
Rectangle:
pos: self.pos
size: self.size
Button:
pos_hint: {'center_x': 0.5}
size_hint: 0.5, 0.7
halign: 'center'
valign: 'middle'
text: 'PCR'
font_size: 40
size: self.texture_size
text_size: self.width, None
AnchorLayout:
canvas:
Color:
rgba: 0.1, 0.1, 1, 0.9
Rectangle:
pos: self.pos
size: self.size
Button:
pos_hint: {'center_x': 0.5}
size_hint: 0.5, 0.7
halign: 'center'
valign: 'middle'
text: 'Electrophoresis'
font_size: 40
size: self.texture_size
text_size: self.width, None
batchscreen.kv
<Row#BoxLayout>:
canvas.before:
Color:
rgba: 0.5, 0.5, 0.5, 1
Rectangle:
size: self.size
pos: self.pos
value: ''
Button:
text: root.value
font_size: sp(80)
on_press: print(f'pressed button {root.value}')
<BatchScreen>:
rv: rv #to expose the widget
FloatLayout:
canvas:
Color:
rgba: hex('c6e2ff')
Rectangle:
pos: self.pos
size: self.size
FloatLayout:
canvas.before:
Color:
rgba: hex('b3b3ff')
RoundedRectangle:
radius: 0,0,25,25
pos: self.pos
size: self.size
pos_hint: {'top':1}
size_hint: 1, .1
Label:
id: lb
text: 'User'
font_size: 60
pos_hint: {'top': 1, 'x': .15}
size_hint: .2, .8
RoundButton:
text: 'Sign Out'
font_size: 40
on_release: print('Sign Out pressed')
pos_hint: {'top': .95, 'x': .55}
size_hint: .4, .8
BoxLayout:
canvas.before:
Color:
rgba: hex('eaec3c')
Rectangle:
pos: self.pos
size: self.size
pos_hint: {'center_x':.5,'center_y':.5}
size_hint: 0.9,0.8
RecycleView:
id: rv
viewclass: 'Row'
scroll_type: ['bars', 'content']
scroll_wheel_distance: dp(114)
bar_width: dp(10)
RecycleBoxLayout:
default_size: None,100
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
GridLayout:
cols:3
canvas.before:
Color:
rgba: hex('969c9c')
Rectangle:
pos: self.pos
size: self.size
pos_hint: {'y': 0}
size_hint: 1, .1
RoundButton:
id: add_batch
text: 'Add Batch'
font_size: 30
on_press: root.manager.transition = SlideTransition(direction="left")
on_release: root.manager.current = 'add_batch_screen'
pos_hint: {'center_y': .5, 'x': .05}
size_hint: .4, .8
back_color: hex('62fd00')
RoundButton:
text: 'Remove Batch'
font_size: 30
halign: 'center'
valign: 'middle'
size: self.texture_size
text_size: self.width, None
on_release: print('Remove pressed')
on_release: print(root.manager.ids.batch_screen.rv.data)
pos_hint: {'center_y': .5, 'x': .55}
size_hint: .4, .8
back_color: hex('fd0000')
RoundButton:
text: 'Back'
font_size: 30
halign: 'center'
valign: 'middle'
size: self.texture_size
text_size: self.width, None
on_press: print('Back pressed')
on_release: root.manager.current = 'home_screen'
pos_hint: {'center_y': .5, 'x': .55}
size_hint: .4, .8
back_color: hex('0000ff')
add_batch_screen.kv
<AddBatchScreen>:
canvas:
Color:
rgba: 0,0,1,1
Rectangle:
pos: self.pos
size: self.size
CapitalInput:
id: capital_input
size_hint: .9, .15
pos_hint: {'center_x': .5, 'y': .6}
font_size: 40
padding: [0, (self.height-self.line_height)/2]
hint_text: 'Batch No.'
multiline: False
halign: 'center'
Button:
id: addbtn
text: 'Add'
size_hint: .4, .08
pos_hint: {'center_x': .5, 'y': .2}
on_press: app.insert(capital_input.text) if capital_input.text != '' else None
on_release: capital_input.text = ''
Button:
text: 'Batch List'
size_hint: .4, .08
pos_hint: {'center_x': .5, 'y': .1}
on_press: root.manager.transition = SlideTransition(direction="right")
on_release: root.manager.current = 'batch_screen'
on_release: print(root.manager.ids.batch_screen.rv.data)
As this is a lot of code you will have a hard time finding someone to give you a specific answer. Without looking through all of your code, yes it is possible to have multiple instances of a screen with unique data. This is exactly the use case of class instances. You simply need to pass a variable, list or object into the instance. I will give you a short example, then you should be able to figure it out yourself for your code.
class MyReusableScreen(Screen):
def __init__(self, data, **kwargs):
super(MyReusableScreen, self).__init__(**kwargs)
self.data = data
mylabel = Label(text=self.data['mylabel_text'])
We added the attribute data to the class. Now we have to pass the data when we initialize the class instance
data1 = {'mylabel_text': 'first label'}
data2 = {'mylabel_text': 'second label'}
screen1 = MyReusableScreen(data=data1)
screen2 = MyReusableScreen(data=data2)
Like this we added unique label texts to the class instances labels. I guess you should now be able to build it up on your own. In case you defined a label in kv language, give it an id like for exanple id: mylabel and then assign the data value like this within you screen mylabel.text = self.data['mylabel_text']. I hope this helps you and if you struggle with something just give me a sign.

How to use the RST module in Kivy?

I'm creating a fitness/nutrition app in Kivy. The problem is that most of the screens involve text for the viewer to read and I don't want the text to be just plain old text like that of a .txt file. I tried looking for something and I found there is a RST rendering module that will make my text look good but after trying for a couple of days, I can't seem to get it working with my code. Also I want to put the text that I will be using with RST into a seperate file so I can keep my code clean, how would I be able to do that?
Python Code(main.py):
import kivy
kivy.require('1.9.0')
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.stacklayout import StackLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ListProperty, StringProperty, OptionProperty, VariableListProperty
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.graphics import *
from kivy.base import runTouchApp
from kivy.uix.label import Label
class MainScreen(Screen):
pass
class NutritionScreen(Screen):
pass
class FitnessScreen(Screen):
pass
class CalorcalcScreen(Screen):
pass
class BigsixScreen(Screen):
pass
class ProteinScreen(Screen):
pass
class CarbScreen(Screen):
pass
class FatScreen(Screen):
pass
class VitaminScreen(Screen):
pass
class MineralScreen(Screen):
pass
class WaterScreen(Screen):
pass
class SuppleScreen(Screen):
pass
class DietScreen(Screen):
pass
class ExerciseScreen(Screen):
pass
class WorkoutplanScreen(Screen):
pass
class ScreenManagement(ScreenManager):
pass
presentation = Builder.load_file("nutrifit.kv")
class NutrifitApp(App):
def build(self):
return presentation
nfApp = NutrifitApp()
nfApp.run()
Kivy Code(nutrifit.kv):
#: import FadeTransition kivy.uix.screenmanager.FadeTransition
ScreenManagement:
transition: FadeTransition()
MainScreen:
NutritionScreen:
FitnessScreen:
CalorcalcScreen:
BigsixScreen:
SuppleScreen:
DietScreen:
ExerciseScreen:
WorkoutplanScreen:
ProteinScreen:
CarbScreen:
FatScreen:
VitaminScreen:
MineralScreen:
WaterScreen:
<MainScreen>:
name: 'main'
GridLayout:
cols: 1
rows: 3
spacing: 1
padding: 1
Button:
text: "Nutrition"
font_size: 25
on_release: app.root.current = "nutrition"
Button:
text: "Fitness"
font_size: 25
on_release: app.root.current = "fitness"
################################################################################
<NutritionScreen>:
name: 'nutrition'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Home'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "main"
Label:
text: 'Nutrition'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"center": 1, "top": 1}
BoxLayout:
orientation: 'vertical'
size_hint: 1, .9
Button:
text: "Caloric Calculator"
font_size: 25
on_release: app.root.current = "calorcalc"
Button:
text: "The Big Six"
font_size: 25
on_release: app.root.current = "bigsix"
Button:
text: "Supplementation"
font_size: 25
on_release: app.root.current = "supple"
Button:
text: "Diets"
font_size: 25
on_release: app.root.current = "diet"
<CalorcalcScreen>:
name: 'calorcalc'
<BackBar#ButtonBehavior+BoxLayout>:
orientation: 'horizontal'
bgcolor: [1, 0, 0, 1]
on_press: self.bgcolor = [1, 0, 0, .5]
on_release: self.bgcolor = [1, 0, 0, 1]
canvas:
Color:
rgba: root.bgcolor
Rectangle:
pos: self.pos
size: self.size
Label:
text: '<--'
size_hint_x: None
width: root.height
Label:
text: 'Current name'
text_size: self.size
halign: 'left'
valign: 'middle'
RstDocument:
text: root.text
<BigsixScreen>:
name: 'bigsix'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "nutrition"
GridLayout:
cols: 2
rows: 3
size_hint: 1, .9
Button:
text: 'Protein'
on_release: app.root.current = 'protein'
Button:
text: 'Carbohydrates'
on_release: app.root.current = 'carb'
Button:
text: 'Fats'
on_release: app.root.current = 'fat'
Button:
text: 'Vitamins'
on_release: app.root.current = 'vitamin'
Button:
text: 'Minerals'
on_release: app.root.current = 'mineral'
Button:
text: 'Water'
on_release: app.root.current = 'water'
<ProteinScreen>:
name: 'protein'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "bigsix"
Label:
text: 'Protein'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
FloatLayout:
Label:
text: 'this is protein'
pos_hint: {"center_x": .5, "center_y": .5}
<CarbScreen>:
name: 'carb'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "bigsix"
Label:
text: 'Carbohydrates'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
FloatLayout:
Label:
text: 'this is carbs'
pos_hint: {"center_x": .5, "center_y": .5}
<FatScreen>:
name: 'fat'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "bigsix"
Label:
text: 'Fats'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
FloatLayout:
Label:
text: 'this is fats'
pos_hint: {"center_x": .5, "center_y": .5}
<MineralScreen>:
name: 'mineral'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "bigsix"
Label:
text: 'Minerals'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
FloatLayout:
Label:
text: 'this is minerals'
pos_hint: {"center_x": .5, "center_y": .5}
<VitaminScreen>:
name: 'vitamin'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "bigsix"
Label:
text: 'Vitamins'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
FloatLayout:
Label:
text: 'this is vitamins'
pos_hint: {"center_x": .5, "center_y": .5}
<WaterScreen>:
name: 'water'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "bigsix"
Label:
text: 'Water'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
FloatLayout:
Label:
text: 'this is water'
pos_hint: {"center_x": .5, "center_y": .5}
<SuppleScreen>:
name: 'supple'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "nutrition"
Label:
text: 'Supplementation'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
BoxLayout:
orientation: 'vertical'
size_hint: 1, .9
<DietScreen>:
name: 'diet'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "nutrition"
Label:
text: 'Diets'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
BoxLayout:
orientation: 'vertical'
size_hint: 1, .9
################################################################################
<FitnessScreen>:
name: 'fitness'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Home'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "main"
Label:
text: 'Fitness'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
BoxLayout:
orientation: 'vertical'
size_hint: 1, .9
Button:
text: "Exercises"
font_size: 25
on_release: app.root.current = "exercise"
Button:
text: "The Big Six"
font_size: 25
on_release: app.root.current = "workoutplan"
<WorkoutplanScreen>:
name: 'workoutplan'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "fitness"
Label:
text: 'Workout Plans'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
BoxLayout:
orientation: 'vertical'
size_hint: 1, .9
<ExerciseScreen>:
name: 'exercise'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "fitness"
Label:
text: 'Exercises'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
BoxLayout:
orientation: 'vertical'
size_hint: 1, .9
This is if I set it to vertical:
first example
This is if I enter the parameters:
size_hint: .5, .1
pos_hint: {"x": 0, "top": 1}
second example
How to use RST Document in Kivy?
Rreference: reStructuredText renderer
Reading text from an input File:
1. Create an input File - inFile.txt
Create a file called "inFile.txt" with the following text:
.. _top:
Hello world
===========
This is an **emphased text**, some ``interpreted text``.
And this is a reference to top_::
$ print("Hello world")
2. Edit class CalorcalcScreen
Replaced "pass" with the following code in your class CalorcalcScreen(Screen):
class CalorcalcScreen(Screen):
text = ""
with open("inFile.txt") as fobj:
for line in fobj:
text += line
3. Edit kv Rule file - nutrifit.kv
At <CalcorcalcScreen>, replace "Label" with "RstDocument" and remove "document = RstDocument..."
<CalorcalcScreen>:
name: 'calorcalc'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "nutrition"
Label:
text: ''
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
BoxLayout:
orientation: 'vertical'
size_hint: 1, .9
RstDocument:
text: root.text
<BigsixScreen>:
New Navigation Bar
Edit kv Rule file
Please update your kv rule file as follow:
<BackBar#ButtonBehavior+BoxLayout>:
orientation: 'horizontal'
bgcolor: [1, 0, 0, 1]
on_press: self.bgcolor = [1, 0, 0, .5]
on_release: self.bgcolor = [1, 0, 0, 1]
canvas:
Color:
rgba: root.bgcolor
Rectangle:
pos: self.pos
size: self.size
Label:
text: '<--'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
Label:
text: 'Current name'
text_size: self.size
halign: 'left'
valign: 'middle'
size_hint: 1, .1
pos_hint: {"right": 1, "top": 1}
<CalorcalcScreen>:
name: 'calorcalc'
BackBar:
BoxLayout:
orientation: 'vertical'
size_hint: 1, .9
RstDocument:
text: root.text
<BigsixScreen>:
Output

Categories

Resources