ScrollView in a anchorlayout. python. kivy - python

practice screen
This is from the .py file
The screens are controlled by screen manager as you can see
class Practice_Page(Screen):
pass
class PracticeList(BoxLayout):
def practicelist(ScrollView):
practicelist.bind(minimum_height=layout.setter('height'))
.KV file:
<Practice_page>:
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: 'background1.png'
AnchorLayout:
anchor_x: 'center'
anchor_y: 'center'
PracticeList:
size: 900,30
size_hint: None,None
do_scroll_x: False
BoxLayout:
orientation: 'vertical'
padding: 10
cols: 1
Button:
text: 'The Real Number System'
on_press: root.manager.current = 'open_topics'
Button:
text: 'Absolute Value'
on_press: root.manager.current = 'open_practice'
Button:
text: 'Operations W/ Integers & Fractions'
on_press: root.manager.current = 'open_topics'
Button:
text: 'Operations W/ Zero'
on_press: root.manager.current = 'open_formulas'
I have about 30 more buttons. I have no idea what I'm doing wrong, any help or suggestions will be very helpful.

AnchorLayout:
anchor_x: 'center'
anchor_y: 'center'
ScrollView:
#size: 900,30
size: self.size
#do_scroll_x: False
GridLayout:
# orientation: 'vertical'
#padding: 10
size_hint_y: None
height: self.minimum_height
cols: 1
Button:
size_hint_y: None
text: 'The Real Number System'
on_press: root.manager.current = 'open_topics'
Button:
size_hint_y: None
text: 'Absolute Value'
on_press: root.manager.current = 'open_practice'
Button:
size_hint_y: None
text: 'Operations W/ Integers & Fractions'
on_press: root.manager.current = 'open_topics'
Button:
size_hint_y: None
text: 'Operations W/ Zero'
on_press: root.manager.current = 'open_formulas'
##MORE BTNS
For anyone who needs it.

Related

Kivy kv creating toolbar with active buttons which change window when pressed

Basically I've created a toolbar with two widgets. One widget (account) should change to a new window when pressed. The other (menu) should open three buttons when it is pressed. When you press on of the three buttons it should also change to a new window.
I don't know how to implement that...
Can anyone help me?
Here's my code:
kv = """
<MenuScreen>:
name: 'mainmenu'
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: 'background.jpg'
Screen:
BoxLayout:
orientation: 'vertical'
MDTopAppBar:
title: 'Fitness App'
left_action_items: [["menu", lambda x: app.navigation_draw()]]
right_action_items: [["account", lambda x: app.callback()]]
elevation:5
MDLabel:
text: 'hello world'
halign: 'center'
BoxLayout:
spacing: 1
orientation: "vertical"
Label:
text: "Welcome back"
font_size: 100
color : 0,0,0,1
Button:
text: 'Get Started'
font_size:100
color: 0, 0, 1, 1
background_color: 0, 0, 0, 1
size_hint: 1, 1
pos_hint: {"x":0, "top":1}
on_release:
root.manager.current = 'screen2'
root.manager.transition.direction = "left"
Button:
text: 'Leave App'
font_size: 100
color: 0, 0, 1, 1
background_color: 0, 0, 0, 1
size_hint: 1, 1
pos_hint: {"x":0, "top":0}
on_release: root.manager.current = app.exit_software()
<Screen2>:
name: 'screen2'
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: 'background.jpg'
BoxLayout:
spacing: 1
orientation: "vertical"
ScrollView:
id: scroll_view
always_overscroll: False
BoxLayout:
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
Label:
id: label
text: "Please choose your problem Area"
color : 0,0,0,1
size_hint: None, None
pos_hint: {"x":0, "top":1}
font_size: 50
size: self.texture_size
Button:
text: 'Shoulders'
font_size: 30
color : 0,0,1,1
on_release:
root.manager.current = 'shoulders'
root.manager.transition.direction = "left"
Button:
text: 'Knees'
font_size: 30
color : 0,0,1,1
background_color: 0, 0, 0, 1
size_hint_y: 1
on_release:
root.manager.current = 'knees'
root.manager.transition.direction = "left"
Button:
text: 'Back'
font_size: 30
color : 0,0,1,1
background_color: 0, 0, 0, 1
size_hint_y: 1
on_release:
root.manager.current = 'back'
root.manager.transition.direction = "left"
Button:
text: 'Back to main menu'
font_size: 30
color : 0,0,1,1
background_color: 0, 0, 0, 1
size_hint_y: 1
on_release:
root.manager.current = 'mainmenu'
root.manager.transition.direction = "right"
<Screen_shoulders>:
name: 'shoulders'
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: 'shoulders.png'
BoxLayout:
spacing: 1
orientation: "vertical"
ScrollView:
id: scroll_view
always_overscroll: False
BoxLayout:
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
Label:
id: label
text: "Choose an activity"
font_size: 50
color : 0,0,0,1
size: self.texture_size
Button:
text: 'Activity1'
font_size: 50
color : 0,0,0,1
size_hint_y: 0.3
on_release:
root.manager.current = 'shouldersActivity1'
root.manager.transition.direction = "right"
Button:
text: 'Activity2'
font_size: 50
color : 0,0,0,1
size_hint_y: 0.3
on_release: app.add_text()
Button:
text: 'Back to main menu'
font_size: 20
color : 0,0,0,1
size_hint_y: 0.1
on_release:
root.manager.current = 'screen2'
root.manager.transition.direction = "right"
ScreenManager:
id: screen_manager
MenuScreen:
id: menu_scr
Screen2:
id: scr_2
"""
class MenuScreen(Screen):
pass
class Screen2(Screen):
pass
class AddTextApp(MDApp):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def build(self):
return Builder.load_string(kv)
def add_text(self):
self.root.ids.scr_2.ids.label.text += f"Some new Text\n"
self.root.ids.scr_2.ids.scroll_view.scroll_y = 0
def callback(self, instance_action_top_appbar_button):
print(instance_action_top_appbar_button)
#staticmethod
def exit_software():
App.get_running_app().stop()
def navigation_draw(self):
# open new window
def callback(self):
# open new window
if __name__ == '__main__':
AddTextApp().run()
I don't know how to make the widgets change window when they're pressed.

From a Popup I need to enter to an external function from my kv kivy

Good day everyone! I created a function and this is located on my screen "Contact" called "resetcampos" in my main.py, then I created a Popup in my kv.file. I need to access my function "resetcampos" from my Button that I have in the Popup. what should I write where it's written "on_press: -----" for accesing to my function "resetcampos" that is in my main.py?
py.main
from tokenize import Number
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.core.spelling import Spelling
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.config import Config
from kivy.properties import StringProperty, NumericProperty
from kivy.uix.recycleview import RecycleView
from kivy.uix.recycleboxlayout import RecycleBoxLayout
from kivy.uix.scrollview import ScrollView
import smtplib
Config.set('graphics', 'width', 360)
Config.set('graphics', 'height', 640)
kv= Builder.load_file('test6.kv')
class MyLayout(Widget):
pass
def spinner_clicked(self,value):
pass
#sm= ScreenManager()
#screen= Screen(name='second')
#self.ids.Label1.text= f'You selected: {value}'
#Define a RecycleView
class RV (Screen):
pass
#Definine our different screens
class FirstWindow(Screen):
#Variables Shopping Cart
var1= StringProperty("images/shoppingcart.png")
var2= StringProperty("images/shoppingcart2.png")
#Functions Items
def list_tornillo(self):
tornillo= self.ids.input_tornillo.text
#tornillo1= str(float(tornillo) * 0.1) if tornillo else "0.0"
tornillo1= str(round(float(tornillo) * 0.1,2)) if tornillo else "0.0"
tornillo2= tornillo1 + "0"
self.ids.label_tornillo.text= tornillo2
def list_andamio(self):
andamio= self.ids.input_andamio.text
andamiod= andamio.isdigit()
if andamiod == True:
andamio1= str(round(float(andamio) * 180,2)) if andamio else "0.0"
andamio2= andamio1 + "0"
self.ids.label_andamio.text= andamio2
else:
self.ids.input_andamio.text= "0"
def list_vigueta(self):
vigueta= self.ids.input_vigueta.text
vigueta1= str(round(float(vigueta) * 200,2)) if vigueta else "0.0"
vigueta2= vigueta1 + "0"
self.ids.label_vigueta.text= vigueta2
def list_perno(self):
perno= self.ids.input_perno.text
perno1= str(round(float(perno) * 0.20,2)) if perno else "0.0"
perno2= perno1 + "0"
self.ids.label_perno.text= perno2
def list_tuerca(self):
tuerca= self.ids.input_tuerca.text
tuerca1= str(round(float(tuerca) * 0.35,2)) if tuerca else "0.0"
tuerca2= tuerca1 + "0"
self.ids.label_tuerca.text= tuerca2
#self.ids.input_tornillo.text= self.ids.label_tornillo.text
def press_on(self):
self.ids.input_tornillo.text= self.ids.label_tornillo.text
#self.ids.my_label.text= "You Pressed the Button"
#self.ids.Shoppingcart1.source= self.var2
def press_off(self):
self.ids.Shoppingcart1.source= self.var1
class SecondWindow(Screen):
pass
class ThirdWindow(Screen):
pass
class FourthWindow(Screen):
def message(self):
pass
def resetcampos (self):
#self.window_manager.get_screen("Contact").ids.nombre.text = "" - Enter another class
self.ids.nombre.text = ""
self.ids.telefono.text = ""
self.ids.correo.text = ""
self.ids.asunto.text = ""
self.ids.mensaje.text = ""
class WindowManager(ScreenManager):
pass
class AwesomeApp(App):
def build(self):
return MyLayout()
if __name__ == '__main__':
AwesomeApp().run()
Kv.Main
<MyLayout>
BoxLayout:
orientation:"vertical"
size: root.width, root.height
GridLayout:
cols:3
rows:3
size_hint: 1,None
height: 65
Spinner:
id: spinner_id
text: "Menu"
values: ["Catalogue","Buy","Payment Methods", "Contact"]
on_text: root.spinner_clicked(spinner_id.text)
on_text: window_manager.current = self.text # uses an id defined in the WindowManager section
#on_text: root.manager.current= "second" - Just work in Screens
Image:
source: 'images/ferrepluslogo2.png'
Button:
text:"Buy"
WindowManager:
id: window_manager
FirstWindow:
SecondWindow:
ThirdWindow:
FourthWindow:
<FirstWindow>:
name: "Catalogue"
BoxLayout:
orientation:'vertical'
pos_hint: {'top': 1}
size: root.width, root.height
size_hint_y: .55
GridLayout:
size:(root.width, root.height)
size_hint_x: None
size_hint_y: None
cols:4
height: self.minimum_height
Label:
text: "Items"
#font_size: 25
Label:
text: "Number"
Label:
text: "Price"
Label:
text: "Add to Cart"
ScrollView:
size_hint_y: .80
pos_hint: {'x':0, 'y': .11}
do_scroll_x: True
do_scroll_y: True
GridLayout:
size:root.width, root.height
size_hint_x: None
size_hint_y: None
cols:4
#height: self.minimum_height
#Label:
# text: "Items"
#font_size: 25
#Label:
# text: "Number"
#Label:
# text: "Price"
#Label:
# text: "Add to Cart"
Label:
text: "Tornillos"
text_size: self.size
halign: 'center'
valign: 'bottom'
Image:
id: image_tornillos
allow_stretch: True
keep_ratio: True
size_hint: 0.2,0.2
width: 60
height: 80
#pos_hint: {'center_x':1, 'center_y':1}
source: "images/tornillo.png"
center_x: self.parent.center_x
center_y: self.parent.center_y+10
TextInput:
id: input_tornillo
text: ""
halign: "right"
font_size: 18
multiline: True
on_text: root.list_tornillo()
#size_hint: (1, .15)
Label:
id: label_tornillo
text: "0.0"
#text: root.ids.input_tornillo.text*2
Button:
id: shopping1
#text: "Hello"
#font_size: 32
allow_stretch: True
keep_ratio: True
size_hint: .25,.30
pos_hint: {'center_x':0.5, 'center_y':0.5}
background_color: 0,0,0,0
#on_press: root.press_on()
#on_release: root.press_off()
on_press: root.ids.Shoppingcart1.source= root.var2
on_release: root.ids.Shoppingcart1.source= root.var1
Image:
id: Shoppingcart1
allow_stretch: True
keep_ratio: True
size_hint: 0.5,0.5
width: 60
height: 60
pos_hint: {'center_x':0.5, 'center_y':0.5}
source: root.var1
center_x: self.parent.center_x
center_y: self.parent.center_y
#------------------------
Label:
text: "Andamios"
text_size: self.size
halign: 'center'
valign: 'bottom'
Image:
id: image_andamios
allow_stretch: True
keep_ratio: True
size_hint: 0.2,0.2
width: 60
height: 80
#pos_hint: {'center_x':1, 'center_y':1}
source: "images/Andamios.png"
center_x: self.parent.center_x
center_y: self.parent.center_y
TextInput:
id: input_andamio
text: ""
halign: "right"
font_size: 18
#size_hint: (1, .15)
on_text: root.list_andamio()
Label:
id: label_andamio
text: "0.0"
Button:
id: shopping2
#text: "Hello"
#font_size: 32
allow_stretch: True
keep_ratio: True
size_hint: .25,.30
pos_hint: {'center_x':0.5, 'center_y':0.5}
background_color: 0,0,0,0
#on_press: root.press_on()
#on_release: root.press_off()
on_press: root.ids.Shoppingcart2.source= root.var2
on_release: root.ids.Shoppingcart2.source= root.var1
Image:
id: Shoppingcart2
allow_stretch: True
keep_ratio: True
size_hint: 0.5,0.5
width: 60
height: 60
pos_hint: {'center_x':0.5, 'center_y':0.5}
source: "images/shoppingcart.png"
center_x: self.parent.center_x
center_y: self.parent.center_y
#-----------------------------------------------------------
#Image:
# id: image_viguetas
# allow_stretch: True
# keep_ratio: True
# size_hint: 0.2,0.2
# width: 40
# height: 60
# #pos_hint: {'center_x':1, 'center_y':1}
# source: "images/viguetas.jpg"
# center_x: self.parent.center_x
# center_y: self.parent.center_y
Label:
text: "Viguetas"
text_size: self.size
halign: 'center'
valign: 'bottom'
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: "images/viguetas.jpg"
TextInput:
id: input_vigueta
text: ""
halign: "right"
font_size: 18
#size_hint: (1, .15)
on_text: root.list_vigueta()
Label:
id: label_vigueta
text: "0.0"
Button:
id: shopping3
#text: "Hello"
#font_size: 32
allow_stretch: True
keep_ratio: True
size_hint: .25,.30
pos_hint: {'center_x':0.5, 'center_y':0.5}
background_color: 0,0,0,0
#on_press: root.press_on()
#on_release: root.press_off()
on_press: root.ids.Shoppingcart3.source= root.var2
on_release: root.ids.Shoppingcart3.source= root.var1
Image:
id: Shoppingcart3
allow_stretch: True
keep_ratio: True
size_hint: 0.5,0.5
width: 60
height: 60
pos_hint: {'center_x':0.5, 'center_y':0.5}
source: "images/shoppingcart.png"
center_x: self.parent.center_x
center_y: self.parent.center_y
#------------------------------------------------------------
#Image:
# id: image_pernos
# allow_stretch: True
# keep_ratio: True
# size_hint: 0.2,0.2
# width: 40
# height: 60
# #pos_hint: {'center_x':1, 'center_y':1}
# source: "images/pernos.png"
# center_x: self.parent.center_x
# center_y: self.parent.center_y
Label:
text: "Pernos"
text_size: self.size
halign: 'center'
valign: 'bottom'
canvas.before:
Rectangle:
pos: self.center_x-39, self.center_y-21
#pos: self.pos
size: 77,50
source: "images/pernos.png"
TextInput:
id: input_perno
text: ""
halign: "right"
font_size: 18
#size_hint: (1, .15)
on_text: root.list_perno()
Label:
text: "0.0"
id: label_perno
Button:
id: shopping4
#text: "Hello"
#font_size: 32
allow_stretch: True
keep_ratio: True
size_hint: .25,.30
pos_hint: {'center_x':0.5, 'center_y':0.5}
background_color: 0,0,0,0
#on_press: root.press_on()
#on_release: root.press_off()
on_press: root.ids.Shoppingcart4.source= root.var2
on_release: root.ids.Shoppingcart4.source= root.var1
Image:
id: Shoppingcart4
allow_stretch: True
keep_ratio: True
size_hint: 0.5,0.5
width: 60
height: 60
pos_hint: {'center_x':0.5, 'center_y':0.5}
source: "images/shoppingcart.png"
center_x: self.parent.center_x
center_y: self.parent.center_y
#------------------------------------------------------------
Label:
text: "Tuercas"
text_size: self.size
halign: 'center'
valign: 'bottom'
canvas.before:
Rectangle:
pos: self.center_x-39, self.center_y-21
#pos: self.pos
size: 77,50
source: "images/tuercas.png"
TextInput:
id: input_tuerca
text: ""
halign: "right"
font_size: 18
#size_hint: (1, .15)
on_text: root.list_tuerca()
Label:
id: label_tuerca
text: "0.0"
Button:
id: shopping5
#text: "Hello"
#font_size: 32
allow_stretch: True
keep_ratio: True
size_hint: .25,.30
pos_hint: {'center_x':0.5, 'center_y':0.5}
background_color: 0,0,0,0
#on_press: root.press_on()
#on_release: root.press_off()
on_press: root.ids.Shoppingcart5.source= root.var2
on_release: root.ids.Shoppingcart5.source= root.var1
Image:
id: Shoppingcart5
allow_stretch: True
keep_ratio: True
size_hint: 0.5,0.5
width: 60
height: 60
pos_hint: {'center_x':0.5, 'center_y':0.5}
source: "images/shoppingcart.png"
center_x: self.parent.center_x
center_y: self.parent.center_y
#----------------------------------------------
Label:
text: "Tejas"
text_size: self.size
halign: 'center'
valign: 'bottom'
canvas.before:
Rectangle:
pos: self.center_x-39, self.center_y-21
#pos: self.pos
size: 77,50
source: "images/Teja.png"
TextInput:
id: input_teja
text: ""
halign: "right"
font_size: 18
#size_hint: (1, .15)
Label:
text: "0.0"
Button:
id: shopping6
#text: "Hello"
#font_size: 32
allow_stretch: True
keep_ratio: True
size_hint: .25,.30
pos_hint: {'center_x':0.5, 'center_y':0.5}
background_color: 0,0,0,0
#on_press: root.press_on()
#on_release: root.press_off()
on_press: root.ids.Shoppingcart6.source= root.var2
on_release: root.ids.Shoppingcart6.source= root.var1
Image:
id: Shoppingcart6
allow_stretch: True
keep_ratio: True
size_hint: 0.5,0.5
width: 60
height: 60
pos_hint: {'center_x':0.5, 'center_y':0.5}
source: "images/shoppingcart.png"
center_x: self.parent.center_x
center_y: self.parent.center_y
#----------------------------------------------
Label:
text: "Tableros"
text_size: self.size
halign: 'center'
valign: 'bottom'
canvas.before:
Rectangle:
pos: self.center_x-39, self.center_y-21
#pos: self.pos
size: 77,50
source: "images/tableros.png"
TextInput:
id: input_tablero
text: ""
halign: "right"
font_size: 18
#size_hint: (1, .15)
Label:
text: "0.0"
Button:
id: shopping7
#text: "Hello"
#font_size: 32
allow_stretch: True
keep_ratio: True
size_hint: .25,.30
pos_hint: {'center_x':0.5, 'center_y':0.5}
background_color: 0,0,0,0
#on_press: root.press_on()
#on_release: root.press_off()
on_press: root.ids.Shoppingcart7.source= root.var2
on_release: root.ids.Shoppingcart7.source= root.var1
Image:
id: Shoppingcart7
allow_stretch: True
keep_ratio: True
size_hint: 0.5,0.5
width: 60
height: 60
pos_hint: {'center_x':0.5, 'center_y':0.5}
source: "images/shoppingcart.png"
center_x: self.parent.center_x
center_y: self.parent.center_y
#-------------------------------------------
Button:
text:""
background_color: 0,0,0,0
Button:
text:""
background_color: 0,0,0,0
Button:
text:""
background_color: 0,0,0,0
Button:
text:""
background_color: 0,0,0,0
#------------------------------------------------------------
<RV>:
ScrollView:
size_hint_y: .73
pos_hint: {'x':0, 'y': .11}
do_scroll_x: True
do_scroll_y: True
GridLayout:
size:(root.width, root.height)
size_hint_x: None
size_hint_y: None
cols:2
height: self.minimum_height
Button:
text:"las"
Button:
text:"cosas"
Button:
text:"de la vida"
Button:
text:"las"
Button:
text:"cosas"
Button:
text:"de la vida"
<SecondWindow>:
name: "Buy"
BoxLayout:
orientation: "vertical"
size: root.width, root.height
Label:
text: "Buy Screen"
font_size: 32
<ThirdWindow>:
name: "Payment Methods"
BoxLayout:
orientation: "vertical"
size: root.width, root.height
Label:
text: "Payment Methods Screen"
font_size: 32
<FourthWindow>:
name: "Contact"
BoxLayout:
orientation: "vertical"
#pos_hint: {'top': 1}
#size: root.width, root.height
#size_hint_y: .55
Label:
id:Escribir
text:" Escríbenos:"
pos_hint: {'top': 1}
size: root.width, root.height
size_hint_y: .55
font_size: 20
bold: True
#----
#text_size: self.size
#valign: 'center'
#halign: 'left'
GridLayout:
#padding: 15
cols:2
#size_hint: None,None
#height: 65
#size_hint: .7,1
BoxLayout:
size_hint: 0.5,1
orientation:"vertical"
Label:
text:"Nombre:"
Label:
text:"Telefono:"
Label:
text:"Email:"
Label:
text:"Asunto:"
BoxLayout:
padding: [0,0,10,0] #left, top, right, bottom
orientation:"vertical"
TextInput:
text: ""
id: nombre
TextInput:
text: ""
id: telefono
TextInput:
text: ""
id:correo
TextInput:
text: ""
id: asunto
GridLayout:
cols:2
#size_hint: .7,1
Label:
text:"Mensaje:"
size_hint: .5,1
BoxLayout:
orientation:"vertical"
padding: [0,0,10,0]
TextInput:
id:mensaje
BoxLayout:
orientation:"vertical"
Label:
text: ""
pos_hint: {'top': 1}
size: root.width, root.height
size_hint_y: .55
GridLayout:
cols:3
Label:
text: ""
Button:
text:"Enviar Mensaje"
on_press: root.message()
on_press: Factory.MyPopup().open()
Label:
text: ""
Label:
text:""
Label:
text: " Contacto:"
font_size: 20
bold: True
#pos_hint: {'top': 1}
#size: root.width, root.height
#size_hint_y: .55
GridLayout:
cols: 2
BoxLayout:
orientation:"vertical"
#size_hint: .3,1
Label:
text:" Telefono:"
size_hint: .2,1
Label:
text:"Email:"
BoxLayout:
orientation:"vertical"
padding: [0,0,90,0]
Label:
text:"198797978"
Label:
text:"washington#hotmail.com"
Label:
text: ""
Label:
text: ""
#:import Factory kivy.factory.Factory
<MyPopup#Popup>
auto_dismiss: False
size_hint: 0.8,0.2
pos_hint: {"x": 0.1, "top":0.9}
title: "Atención"
BoxLayout:
orientation:"vertical"
size: root.width, root.height
Label:
text: "Su mensaje fue enviado exitosamente"
font_size: 15
Button:
text:"Cerrar"
font_size: 15
on_release: root.dismiss()
on_press: main.FourthWindow.resetcampos()
#on_press: window_manager.resetcampos()

Kivy ScrollView does not fill the entire window

I am trying to write a Kivy file that includes a scrollview below the MDToolBar and above MDBottomNavigation. I cannot get the ScrollView content to fill the entire screen below the ToolBar and above the BottomNav. It only fills have the window vertical span. If I eliminate the toolbar and bottom nave the scrollview fills the entire vertical span without a problem. Any tips on getting the scrollview contents to fill the completely would be appreciated. I tried changing indentation and that did not work. Thanks in advance.
Screenshot
# WINDOW MANAGER
WindowManager:
MainWindow:
AboutWindow:
<MainWindow>:
name: "main"
BoxLayout:
orientation: "vertical"
MDToolbar:
title: "Solar Weather"
MDLabel:
id: sub_title
text: "SUB TITLE"
halign: "center"
size_hint: (1,0.2)
ScrollView:
size: self.size
GridLayout:
size_hint_y: None
height: self.minimum_height
width: self.minimum_width
cols: 2
spacing: "20dp"
padding: "20dp"
# SOLAR FLUX BOX #
MDCard:
orientation: "vertical"
padding: "8dp"
size_hint: 1, None
height: "210dp"
elevation: 5
MDLabel:
id: flux
text: "Solar Wind"
halign: "center"
MDLabel:
id: flux_value_id
text: ""
halign: "center"
MDLabel:
id: flux_time_id
text: ""
halign: "center"
MDRaisedButton:
text: "Refresh"
pos_hint: {"x":0}
size_hint: 1,1
md_bg_color: app.theme_cls.primary_color
on_release: root.calc_solar_flux()
MDRaisedButton:
text: "Details"
pos_hint: {"x":0}
size_hint: 1,1
md_bg_color: app.theme_cls.primary_color
on_release: root.calc_solar_flux()
MDCard:
orientation: "vertical"
padding: "8dp"
size_hint: 1, None
height: "210dp"
elevation: 5
MDCard:
orientation: "vertical"
padding: "8dp"
size_hint: 1, None
height: "210dp"
elevation: 5
MDCard:
orientation: "vertical"
padding: "8dp"
size_hint: 1, None
height: "210dp"
elevation: 5
MDLabel:
text: "Solar Wind"
halign: "center"
MDRaisedButton:
text: "Go Back"
md_bg_color: app.theme_cls.primary_color
on_release:
root.manager.current = "main"
root.manager.transition.direction = "right"
MDBottomNavigation:
MDBottomNavigationItem:
name: 'Dark'
text: "Dark Theme"
icon: 'brightness-2'
on_tab_release: root.dark_theme()
MDBottomNavigationItem:
name: 'Light'
text: "Light Theme"
icon: 'brightness-5'
on_tab_release: root.light_theme()
MDBottomNavigationItem:
name: 'info'
text: "About"
icon: 'information'
on_tab_release:
root.manager.current = "about"
root.manager.transition.direction = "left"
MDBottomNavigationItem:
name: 'option 2'
text: "Relaod"
icon: 'reload'
#: include about.kv
I hope this helps someone else. I had to rewrite the kv file fairly extensively but it works.
# WINDOW MANAGER
WindowManager:
MainWindow:
AboutWindow:
<MainWindow>:
name: "main"
BoxLayout:
orientation: "vertical"
MDLabel:
id: title
text: "SOLAR WEATHER"
halign: "left"
size_hint: (1,0.1)
padding_x: 20
pos_hint: {"x":0.0,"y":0.9}
md_bg_color: app.theme_cls.primary_dark
MDLabel:
id: sub_title
text: "SUB TITLE"
halign: "center"
size_hint: (1,0.1)
pos_hint: {"x":0.0,"y":0.8}
ScrollView:
size: self.size
pos_hint: {"x":0,"y":0.1}
GridLayout:
size_hint_y: None
height: self.minimum_height
width: self.minimum_width
cols: 2
spacing: "20dp"
padding: "20dp"
# SOLAR FLUX BOX #
MDCard:
orientation: "vertical"
padding: "8dp"
spacing: "8dp"
size_hint: 1, None
height: "210dp"
elevation: 5
MDLabel:
id: flux
text: "SOLAR FLUX"
halign: "center"
MDLabel:
id: flux_value_id
markup: True
text: ""
halign: "center"
MDLabel:
id: flux_time_id
text: ""
halign: "center"
MDRaisedButton:
text: "Refresh"
pos_hint: {"x":0}
size_hint: 1,1
md_bg_color: app.theme_cls.primary_color
on_release: root.calc_solar_flux()
MDRaisedButton:
text: "Details"
pos_hint: {"x":0}
size_hint: 1,1
md_bg_color: app.theme_cls.primary_color
on_release: root.calc_solar_flux()
# SUN SPOT NUMBER BOX #
MDCard:
orientation: "vertical"
padding: "8dp"
spacing: "8dp"
size_hint: 1, None
height: "210dp"
elevation: 5
MDLabel:
id: ssn
text: "SUN SPOT NUMBER"
halign: "center"
MDLabel:
id: ssn_value_id
markup: True
text: ""
halign: "center"
MDLabel:
id: ssn_date_id
text: ""
halign: "center"
MDRaisedButton:
text: "Refresh"
pos_hint: {"x":0}
size_hint: 1,1
md_bg_color: app.theme_cls.primary_color
on_release: root.calc_sunspot_number()
MDRaisedButton:
text: "Details"
pos_hint: {"x":0}
size_hint: 1,1
md_bg_color: app.theme_cls.primary_color
on_release: root.calc_sunspot_number()
MDCard:
orientation: "vertical"
padding: "8dp"
size_hint: 1, None
height: "210dp"
elevation: 5
MDCard:
orientation: "vertical"
padding: "8dp"
spacing: "8dp"
size_hint: 1, None
height: "210dp"
elevation: 5
MDLabel:
text: "Solar Wind"
halign: "center"
MDRaisedButton:
text: "Go Back"
md_bg_color: app.theme_cls.primary_color
on_release:
root.manager.current = "main"
root.manager.transition.direction = "right"
GridLayout:
size_hint_y: None
height: self.minimum_height
width: self.minimum_width
cols: 3
spacing: "80dp"
padding: "20dp"
MDIconButton:
name: "Dark"
text: "Dark Theme"
icon: "brightness-2"
on_release: root.dark_theme()
md_bg_color: app.theme_cls.primary_dark
MDIconButton:
id: light_theme_icon
name: "Light"
text: "Light Theme"
icon: "brightness-5"
on_release: root.light_theme()
md_bg_color: app.theme_cls.primary_dark
MDIconButton:
name: "info"
text: "About"
icon: "information"
on_release:
root.manager.current = "about"
md_bg_color: app.theme_cls.primary_dark
#: include about.kv

How do I align text inside a kivy label within a .kv file?

I try to make a gui for a text based RPG, and now I want to align the text of some labels to the top left, but "halign:" and "valign:" don't seem to do anything.
So how do I align the text inside my labels? Is there something I have done horribly wrong?
This is how the GUI looks at this moment and I marked where the text should be with green arrows:
This is how my .kv file looks:
BoxLayoutExample:
<BackgroundColor#Widget>:
background_color: 1,1,1,1
canvas.before:
Color:
rgba: root.background_color
Rectangle:
size: self.size
pos: self.pos
<BackgroundLabel#Label+BackgroundColor>:
background_color: 0, 0, 0, 0
<BoxLayoutExample>:
orientation: "vertical"
BoxLayout:
orientation:"horizontal"
BackgroundLabel:
background_color: 1,0,0,1
text: "Placeholder Text\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST"
halign: "left"
valign: "top"
font_size: "10sp"
size_hint: .5, 1
Label:
text: "Placeholder Map/Enemy #TEST TEST TEST TEST TEST \nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST"
halign: "left"
valign: "top"
size_hint: 1, 1.3
BoxLayout:
orientation:"vertical"
size_hint: .5, 1
Label:
background_color: 1,1,1,.5
text: "Placeholder Stats\nHP\nMP\nDMG\nXP\nLVL"
halign: "left"
valign: "top"
size_hint: 1, .3
ScrollView:
size_hint: 1, .7
scroll_distance: 100
Label:
text: "Placeholder Inventory\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST"
size_hint: None, None
size: self.texture_size
halign: "left"
valign: "top"
BoxLayout:
orientation: "horizontal"
size: "60dp","60dp"
size_hint: None,None
Label:
size: "60dp","60dp"
size_hint: None,None
Button:
text: "go\nnorth"
size: "60dp","60dp"
size_hint: None,None
Label:
size: "60dp","60dp"
size_hint: None,None
BoxLayout:
orientation: "horizontal"
size: "180dp","60dp"
#pos: "0dp","60dp"
size_hint: None,None
Button:
text: "go\nwest"
size: "60dp","60dp"
#pos: "0dp","60dp"
size_hint: None,None
pos_hint: {"x":0}
Button:
text: "go\nsouth"
size: "60dp","60dp"
size_hint: None,None
Button:
text: "go\neast"
size: "60dp","60dp"
#pos: "0dp","60dp"
size_hint: None,None
Label:
size: "60dp","60dp"
size_hint: None,None
Button:
text: "use\nitem"
size: "60dp","60dp"
size_hint: None,None
Button:
text: "equip\ngear"
size: "60dp","60dp"
size_hint: None,None
Button:
text: "unequip\ngear"
size: "60dp","60dp"
size_hint: None,None
Thanks for your help, I really appreciate it.
You need to add this argument in your label:
text_size: self.size
Then the halign and valign arguments will work properly, for example:
Label:
text: "Placeholder Map/Enemy #TEST TEST TEST TEST TEST \nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST\nTEST"
text_size: self.size
halign: "left"
valign: "top"
size_hint: 1, 1.3
More details in the official kivy documentation.

KivyMD Remove a Expansion Panel

I'm having trouble finding the solution in how to remove an expansion panel which inside of it it contains TwoLineAvatarListItem with a IconLeftWidget, and below that is a MDCard with two MDlabels for text. I've tried to use self.root.ids.remove_widget() but it does not do anything. I've tried many ways and have not found the solution. Here is the code please feel free to view. Thanks
kv. file
<Content>:
adaptive_height: True
#size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
TwoLineAvatarListItem:
text: "Message"
secondary_text: 'to: #gmail.com'
IconLeftWidget:
icon: 'email'
MDCard:
orientation: "vertical"
padding: "8dp"
size_hint: None, None
size: "280dp", "180dp"
pos_hint: {"center_x": .5, "center_y": .5}
MDLabel:
text: "Title"
theme_text_color: "Secondary"
size_hint_y: None
height: self.texture_size[1]
MDSeparator:
height: "1dp"
MDLabel:
text: "Body"
ScreenManager:
Screen:
id: messages
name: 'messages'
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Messages Center"
elevation:8
MDIconButton:
icon: 'arrow-left'
on_press: screen_manager.current = "main_app_screen"
theme_text_color: 'Custom'
md_bg_color: app.theme_cls.primary_color
ScrollView:
GridLayout:
cols: 1
size_hint_y: None
height: self.minimum_height
id: box
.py python file
class DemoApp(MDApp):
def on_start(self):
for i in range(10):
panel = MDExpansionPanel(
icon=f"{images_path}folder.png",
content=Content(),
panel_cls=MDExpansionPanelTwoLine(
text='',
secondary_text=str(i) + ' email: xxxxx#gmail.com',))
self.root.ids.box.add_widget(panel)
DemoApp().run()
<Content>:
[...]
MDCard:
[...]
MDRaisedButton:
text: "REMOVE"
on_release: app.remove(root)
[...]
class DemoApp(MDApp):
[...]
def remove(self, content):
self.root.ids.box.remove_widget(content.parent)

Categories