How do I prevent elements from trasitioning in kivy? - python

hope you are safe during the pandemics.
I'd like to have a fixed header on the screen while transitioning from a screen to another. My code is as follows:
from kivy.app import App
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen, ScreenManager
# Window.fullscreen = True
Window.size = (800, 480)
Window.borderless = "1"
Window.clearcolor = (0.976470588235, 0.976470588235, 0.976470588235, 1)
class Launch(App):
def build(self):
kv_file = Builder.load_file("app.kv")
return kv_file
class MainWindow(Screen):
pass
class SecondWindow(Screen):
pass
class WindowManager(ScreenManager):
pass
if __name__ == "__main__":
Launch().run()
and my .kv file,
<Button>:
size_hint: 0.325, 0.3125
WindowManager:
MainWindow:
SecondWindow:
<MainWindow>:
name: "main_window"
FloatLayout:
Label:
canvas.before:
Color:
rgba: 0, 0, 0, 1
Rectangle:
size: self.size
pos: self.pos
text: "Lorem Ipsum"
pos_hint: {"x": 0, "y": (480-50)/480}
size_hint: 1, 50/480
Button:
pos_hint: {"x": 0.14583375, "y": 0.50694375}
text: "OP1"
Button:
pos_hint: {"x": 0.14583375, "y": 0.09722292}
text: "OP2"
Button:
pos_hint: {"x": 0.52916625, "y": 0.50694375}
text: "OP3"
Button:
pos_hint: {"x": 0.52916625, "y": 0.09722292}
text: "OP4"
Button:
pos_hint: {"x": 0.88958375, "y":0.38616458}
size_hint: 0.075, 0.144
text: "->"
on_press:
app.root.current = "second_window"
root.manager.transition.direction = "left"
<SecondWindow>:
name: "second_window"
FloatLayout:
Label:
canvas.before:
Color:
rgba: 0, 0, 0, 1
Rectangle:
size: self.size
pos: self.pos
text: "Lorem Ipsum"
pos_hint: {"x": 0, "y": (480-50)/480}
size_hint: 1, 50/480
Button:
pos_hint: {"x": 0.14583375, "y": 0.50694375}
text: "OP1"
Button:
pos_hint: {"x": 0.14583375, "y": 0.09722292}
text: "OP2"
Button:
pos_hint: {"x": 0.52916625, "y": 0.50694375}
text: "OP3"
Button:
pos_hint: {"x": 0.52916625, "y": 0.09722292}
text: "OP4"
Button:
pos_hint: {"x": 0.03541625, "y": 0.38616458}
size_hint: 0.075, 0.144
text: "<-"
on_press:
app.root.current = "main_window"
root.manager.transition.direction = "right"
The way it is, the Label that is on top of the screen changes to itself during the transition and my goal is to make it static as the rest of the screen transits left/right. What can be done to pin this label header?

As inclement already mentioned you have to make a container class and put your Label (header) and the ScreenManager inside
app.py
from kivy.app import App
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
from kivy.uix.widget import Widget
from kivy.uix.floatlayout import FloatLayout
class Launch(App):
def build(self):
kv_file = Builder.load_file("app.kv")
return kv_file
class MainWindow(FloatLayout):
pass
class SecondScreen(Screen):
pass
class FirstScreen(Screen):
pass
if __name__ == "__main__":
Launch().run()
app.kv
<FirstScreen>:
name: 'first'
id: first_window
BoxLayout:
Button:
id: my_button
text:"Hi"
on_release: app.root.manager.current = 'second'
<SecondScreen>:
name: 'second'
id: second_window
BoxLayout:
Button:
text:"Bye"
on_release: app.root.manager.current = 'first'
MainWindow:
manager: manager
BoxLayout:
orientation: 'vertical'
Label:
text: 'Header'
ScreenManager:
id: manager
FirstScreen:
SecondScreen:

Related

How can i make textinput a class variable

I am trying to get TextInput's text from another screen. In the code below I can get the text but my project has multiple functions. So I thought if I can make textinput a class variable it would be eaiser to coding.
Example Code:
.py
from kivy.app import App
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.uix.screenmanager import NoTransition
import requests
class MainPage(Screen):
pass
class ExercisePage(Screen):
def test(self):
link = self.manager.get_screen('mainpage')
a = requests.get(f'{link.ids.http.text}/gpio12On')
def testt(self):
link = self.manager.get_screen('mainpage')
a = requests.get(f'{link.ids.http.text}/gpio12Off')
class MyApp(App):
def build(self):
global sm
sm = ScreenManager(transition=NoTransition())
sm.add_widget(MainPage(name='mainpage'))
sm.add_widget(ExercisePage(name='exercisepage'))
return sm
if __name__ == '__main__':
MyApp().run()
Here is the .kv file
<MainPage>
FloatLayout:
TextInput:
id: http
text: ""
multiline: False
size_hint: 0.5,0.05
pos_hint: {"x": 0.3, "y": 0.8}
Button:
text:"Enter"
size_hint: 0.1,0.06
pos_hint: {"x": 0.82, "y": 0.795}
on_release:
app.root.current = "exercisepage"
<ExercisePage>
FloatLayout:
Button:
text:"test"
size_hint: 0.5,0.075
pos_hint: {"x": 0.2, "top": 0.4}
on_release:
root.test()
Button:
text:"test2"
size_hint: 0.5,0.075
pos_hint: {"x": 0.2, "top": 0.5}
on_release:
root.testt()
What I am trying to do is like this:
class ExercisePage(Screen):
link = self.manager.get_screen('mainpage')
def test(self):
a = requests.get(f'{self.link.ids.http.text}/gpio12On')
def testt(self):
a = requests.get(f'{self.link.ids.http.text}/gpio12Off')
If you define your application root in the kv file, then the ids are available everywhere in that root rule. And then you can define an ObjectProperty in the ExercisePage that refers to the TextInput text. Here is what such a kv file could look like:
ScreenManager:
MainPage:
name: 'mainpage'
FloatLayout:
TextInput:
id: http
text: ""
multiline: False
size_hint: 0.5,0.05
pos_hint: {"x": 0.3, "y": 0.8}
Button:
text:"Enter"
size_hint: 0.1,0.06
pos_hint: {"x": 0.82, "y": 0.795}
on_release:
app.root.current = "exercisepage" # this could also be just root.current = "exercisepage"
ExercisePage:
id: escr
link: http.text # link to the TextInput text
name: 'exercisepage'
FloatLayout:
Button:
text:"test"
size_hint: 0.5,0.075
pos_hint: {"x": 0.2, "top": 0.4}
on_release:
escr.test() # changed to use id
Button:
text:"test2"
size_hint: 0.5,0.075
pos_hint: {"x": 0.2, "top": 0.5}
on_release:
escr.testt() # changed to use id
Then you define the ObjectProperty in the ExercisePage, and use that in the methods:
class ExercisePage(Screen):
link = ObjectProperty(None)
def test(self):
# link = self.manager.get_screen('mainpage')
print(self.link)
# a = requests.get(f'{link.ids.http.text}/gpio12On')
def testt(self):
# link = self.manager.get_screen('mainpage')
print(self.link)
# a = requests.get(f'{link.ids.http.text}/gpio12Off')
And since you define the root widget in the kv file, you can completely eliminate the build() method from your MyApp class.

MDSelectionList properties cannot be modified

I am using an MDSelectionList inside a tab with an MDNavigationRail to switch between screens, however, when I try to customize the MDSelectionList, none of the visual changes apply. I thought that maybe it is a problem with the widget itself but then I separated it and the property changes worked. How can I make the changes apply to the selection list? (I am using kivymd 0.104.2.dev0 from the master branch)
My Code:
from kivy.config import Config
Config.set('graphics', 'width', '850')
Config.set('graphics', 'height', '530')
Config.set('graphics', 'minimum_width', '850')
Config.set('graphics', 'minimum_height', '530')
from kivy.lang import Builder
from kivymd.uix.card import MDCard
from kivymd.uix.tab import MDTabsBase
from kivymd.app import MDApp
class SettingsTab(MDCard, MDTabsBase):
pass
class Example(MDApp):
def __init__(self, **kwargs):
super(Example, self).__init__(**kwargs)
self.kv = Builder.load_string('''
#:kivy 2.0.0
<SettingsTab>:
orientation: "vertical"
size_hint: .95, .95
pos_hint: {"center_x": .5, "center_y": .5}
border_radius: 5
radius: [5]
elevation: 20
BoxLayout:
MDNavigationRail:
color_active: app.theme_cls.primary_color
MDNavigationRailItem:
icon: "list-status"
on_release:
screens.current = "downloads_screen"
MDNavigationRailItem:
icon: "cog"
on_release:
screens.current = "settings"
MDNavigationRailItem:
icon: "information"
on_release:
screens.current = "activity_log"
ScreenManager:
id: screens
Screen:
name: "downloads_screen"
Screen:
name: "activity_log"
Screen:
name: "settings"
MDTabs:
SettingsTab:
title: "DOWNLOAD"
MDSelectionList:
overlay_color: 1, 0, 0, .5
icon_bg_color: 0, 0, 0, 0
icon_check_color: 0, 0, 0, 0
OneLineIconListItem:
text: "Just me!"
IconLeftWidget:
icon: "circle-outline"
pos_hint: {"center_x": .5, "center_y": .5}
OneLineIconListItem:
text: "Just me!"
IconLeftWidget:
icon: "circle-outline"
OneLineIconListItem:
text: "Just me!"
IconLeftWidget:
icon: "circle-outline"
OneLineIconListItem:
text: "Just me!"
IconLeftWidget:
icon: "circle-outline"
SettingsTab:
title: "COLOR"
SettingsTab:
title: "INFO"''')
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Blue"
self.theme_cls.accent_palette = "Teal"
return self.kv
if __name__ == '__main__':
Example().run()
Try something like this.
from kivy.lang import Builder
from kivymd.uix.card import MDCard
from kivymd.uix.tab import MDTabsBase
from kivymd.app import MDApp
kv = ("""
<Check#ILeftBodyTouch+MDCheckbox>:
group: 'group'
size_hint: None, None
size: dp(48), dp(48)
<SettingsTab>:
orientation: "vertical"
size_hint: .95, .95
pos_hint: {"center_x": .5, "center_y": .5}
border_radius: 5
radius: [5,]
elevation: 20
BoxLayout:
MDNavigationRail:
color_active: app.theme_cls.primary_color
MDNavigationRailItem:
icon: "cog"
on_release:
screens.current = "settings"
ScreenManager:
id: screens
Screen:
name: "settings"
MDTabs:
SettingsTab:
title: "DOWNLOAD"
MDList:
spacing: 10
OneLineAvatarIconListItem:
text: "Just me!"
Check:
OneLineAvatarIconListItem:
text: "Just me!"
Check:
OneLineAvatarIconListItem:
text: "Just me!"
Check:
""")
class SettingsTab(MDCard, MDTabsBase):
pass
class Example(MDApp):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.kv = Builder.load_string(kv)
def build(self):
return self.kv
if __name__ == '__main__':
Example().run()

Can a button be used to add another Label to the screen in Kivy

I want the last button in the pop up to add a label to the previous screen with the text of whatever in entered into the text input in the pop up but I cant find a way to do so, is it possible?
I want the button with id add to add a label to screen the List every time it is clicked, and the text of said label should be whatever value put into text inputs with the ids lab, club, and blub
And if it is possible, how can I do it, any help would be greatly appreciated.
Python :
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ObjectProperty
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.lang import Builder
from kivy.uix.popup import Popup
import time
from kivy.properties import StringProperty
class Enter_Name(Screen):
input_1 = StringProperty()
def line(self):
App.get_running_app().root.get_screen('list').lab_text = self.airline.text
pass
class Pop(Screen):
air_craft = StringProperty()
def lad(self):
plane = App.get_running_app().root.get_screen('pop').lab_text = self.airplane.text
self.plane = plane
class List(Screen):
Enter_Name.line
def add(self):
show_popup()
def show_popup():
show = Pop()
pop_up_window = Popup(title="Add Route", content=show, size_hint=(None, None), size=(400, 400))
pop_up_window.open()
class WindowManager(ScreenManager):
pass
kv = Builder.load_file("pot.kv")
class am4(App):
def build(self):
return kv
if __name__ == "__main__":
am4().run()
Kivy :
#:kivy 1.0
WindowManager:
Enter_Name
List
Pop
#_______________________________________________________________________________________________________
#LOGIN
#_______________________________________________________________________________________________________
<Enter_Name>
airline: input_1
name: 'enter_name'
id: enter_nom
FloatLayout:
cols: 3
size: root.size
Label:
text: "Name of Airline?"
size_hint: 1, 0.3
pos_hint: {"x": 0, "top":1}
TextInput:
multiline: False
name: 'input_one'
id: input_1
size_hint: 0.6, 0.06
pos_hint: {"x": 0.20, "top":0.6}
Button:
size_hint: 0.2, 0.1
pos_hint: {"x": 0.4, "top":0.4}
text: "Enter"
on_release:
app.root.current = 'list'
root.line()
#_______________________________________________________________________________________________________
#MAIN
#_______________________________________________________________________________________________________
<List>
lab_text: ''
name: 'list'
FloatLayout:
Label:
text: root.lab_text
size_hint: 1, 0.3
pos_hint: {"x": -0.38, "top":1.1}
font_size: 50
Label:
text: '--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
size_hint: 1, 0.3
pos_hint: {"x": -0.38, "top":1}
font_size: 50
Button:
text: "Add Route"
size_hint: 0.2, 0.1
pos_hint: {"x":0.79, "top":0.99}
on_release: root.add()
<Pop>
name: "pop"
airplane: air_craft
FloatLayout:
Label:
id: lab
text: "Aircraft"
pos_hint: {"x": -0.38, "top":1.45}
Label:
id: club
text: "Departure"
pos_hint: {"x": 0, "top":1.45}
Label:
id: blub
text: "Arrival"
pos_hint: {"x": 0.38, "top":1.45}
TextInput:
multiline: False
name: 'aircraft'
id: air_craft
size_hint: 0.23, 0.06
pos_hint: {"x": 0, "top":0.9}
TextInput:
multiline: False
name: 'departure'
id: leaving
size_hint: 0.23, 0.06
pos_hint: {"x": 0.38, "top":0.9}
TextInput:
multiline: False
name: 'arrival'
id: arriving
size_hint: 0.23, 0.06
pos_hint: {"x": 0.76, "top":0.9}
Button:
size_hint: 0.2, 0.1
pos_hint: {"x": 0.4, "top":0.5}
id: add
text: "Add"
on_release:
root.lad()
Here is a modified version of your code that does what I think you want:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.relativelayout import RelativeLayout
from kivy.properties import ObjectProperty
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.lang import Builder
from kivy.uix.popup import Popup
from kivy.properties import StringProperty
class Enter_Name(Screen):
input_1 = StringProperty()
def line(self):
App.get_running_app().root.get_screen('list').lab_text = self.airline.text
class ListRow(BoxLayout):
ac = StringProperty('')
arr = StringProperty('')
lv = StringProperty('')
class Pop(RelativeLayout):
def lad(self, ac, arr, lv):
list_scr = App.get_running_app().root.get_screen('list')
if ac != '' or arr != '' or lv != '':
box_layout = list_scr.ids.box_layout
box_layout.add_widget(ListRow(ac=ac, arr=arr, lv=lv))
list_scr.pop.dismiss()
class List(Screen):
Enter_Name.line
pop = ObjectProperty(None)
def add(self):
self.pop = show_popup()
def show_popup():
show = Pop()
pop_up_window = Popup(title="Add Route", content=show, size_hint=(None, None), size=(400, 400))
pop_up_window.open()
return pop_up_window
class WindowManager(ScreenManager):
pass
# kv = Builder.load_file("pot.kv")
kv = Builder.load_string('''
#:kivy 1.0
WindowManager:
Enter_Name
List
#_______________________________________________________________________________________________________
#LOGIN
#_______________________________________________________________________________________________________
<Enter_Name>
airline: input_1
name: 'enter_name'
id: enter_nom
FloatLayout:
cols: 3
size: root.size
Label:
text: "Name of Airline?"
size_hint: 1, 0.3
pos_hint: {"x": 0, "top":1}
TextInput:
multiline: False
name: 'input_one'
id: input_1
size_hint: 0.6, 0.06
pos_hint: {"x": 0.20, "top":0.6}
Button:
size_hint: 0.2, 0.1
pos_hint: {"x": 0.4, "top":0.4}
text: "Enter"
on_release:
app.root.current = 'list'
root.line()
#_______________________________________________________________________________________________________
#MAIN
#_______________________________________________________________________________________________________
<List>
lab_text: ''
name: 'list'
BoxLayout:
id: box_layout
orientation: 'vertical'
size_hint_y: None
height: self.minimum_height
pos_hint: {'top':1}
BoxLayout:
orientation: 'vertical'
size_hint: 1, None
height: 50
BoxLayout:
orientation: 'horizontal'
Label:
id: lab1
text: root.lab_text
size_hint_x: 1
#pos_hint: {"x": -0.38, "top":1}
font_size: 50
Button:
text: "Add Route"
size_hint_x: 0.5
#pos_hint: {"x":0.79, "top":1}
on_release: root.add()
Label:
text: '--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
size_hint: 1, 0.3
#pos_hint: {"x": -0.38, "top":0.99}
font_size: 50
<ListRow>:
orientation: 'horizontal'
size_hint: (1, None)
height: self.minimum_height
Label:
text: 'Aircraft: ' + root.ac
halign: 'left'
size_hint: 1, None
height: self.texture_size[1]
Label:
text: 'Leave: ' + root.lv
halign: 'left'
size_hint: 1, None
height: self.texture_size[1]
Label:
text: 'Arrive: ' + root.arr
halign: 'left'
size_hint: 1, None
height: self.texture_size[1]
<Pop>
airplane: air_craft
FloatLayout:
Label:
id: lab
text: "Aircraft"
pos_hint: {"x": -0.38, "top":1.45}
Label:
id: club
text: "Departure"
pos_hint: {"x": 0, "top":1.45}
Label:
id: blub
text: "Arrival"
pos_hint: {"x": 0.38, "top":1.45}
TextInput:
multiline: False
name: 'aircraft'
id: air_craft
size_hint: 0.23, 0.06
pos_hint: {"x": 0, "top":0.9}
TextInput:
multiline: False
name: 'departure'
id: leaving
size_hint: 0.23, 0.06
pos_hint: {"x": 0.38, "top":0.9}
TextInput:
multiline: False
name: 'arrival'
id: arriving
size_hint: 0.23, 0.06
pos_hint: {"x": 0.76, "top":0.9}
Button:
size_hint: 0.2, 0.1
pos_hint: {"x": 0.4, "top":0.5}
id: add
text: "Add"
on_release:
root.lad(air_craft.text, arriving.text, leaving.text)
''')
class am4(App):
def build(self):
return kv
if __name__ == "__main__":
am4().run()
Some of the significant changes that I made:
Redefined the Pop class as extending RelativeLayout instead of Screen and removed Pop from the children of WindowManager.
Defined a ListRow class that is added to the List Screen when the lad() method is called.
Added arguments to the lad() method for information to be added, and added a dismiss() call to close the Popup.
The show_pop() method now returns the created Popup instance which is saved in the List Screen for use of dismiss().
Redesigned the List Screen using a vertical BoxLayout to make adding ListRows simpler.
The kv is loaded using Builder.load_string() in the above code, but that is only for my own convenience.

MDLabels stacked in one place (one above another)

I've some problems with multiple MDLabels in BoxLayout (that is contains by AnchorLayout), so all the MDLabel objects are stacked in one place on the screen!
I dont know how to make them centered and grouped like a list (with spacing and e.g.)
Please, help me with solving that problem!
Thanks a lot and sorry for bad english.
There is my main.py
from kivy.app import App
from kivymd.theming import ThemeManager
from kivymd.label import MDLabel
from kivy.uix.screenmanager import Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.metrics import dp, sp, pt
def toast(text):
from kivymd.toast.kivytoast import toast
toast(text)
class MyScreen(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.menu_items = [
{
"viewclass": "MDMenuItem",
"text": "text%d" % i,
"callback": self.callback,
}
for i in range(1, 3)
]
self.menu_button = None
def change_variable(self, value):
print("\nvalue=", value)
self.VARIABLE = value
print("\tself.VARIABLE=", self.VARIABLE)
def callback(self, *args):
toast(args[0])
class MainApp(App):
title = "KivyMD MDDropdownMenu Demo"
theme_cls = ThemeManager()
def build(self):
return MyScreen()
if __name__ == "__main__":
MainApp().run()
And there is my main.kv file contains:
#:import MDDropdownMenu kivymd.menus.MDDropdownMenu
#:import MDRaisedButton kivymd.button.MDRaisedButton
#:import MDLabel kivymd.label.MDLabel
<MDMenuItem>:
on_release:
app.root.change_variable(self.text)
app.root.menu_button.text = self.text
<MyScreen>:
name: 'myscrn'
AnchorLayout:
anchor_y: 'center'
BoxLayout:
orientation: 'vertical'
size_hint: 0.1, 0.5
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
spacing: dp(10)
MDRaisedButton:
id: mainbutton
size_hint: None, None
size: 3 * dp(48), dp(48)
text: 'MDButton1'
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
opposite_colors: True
on_release:
root.menu_button = mainbutton
MDDropdownMenu(items=root.menu_items, width_mult=4).open(self)
MDRaisedButton:
id: secondbutton
size_hint: None, None
size: 3 * dp(48), dp(48)
text: 'MDButton2'
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
opposite_colors: True
on_release:
root.menu_button = secondbutton
MDDropdownMenu(items=root.menu_items, width_mult=4).open(self)
AnchorLayout:
anchor_y: 'top'
BoxLayout:
orientation: 'vertical'
size_hint: 0.95, 0.5
padding: [0, 0, 0, 0]
spacing: dp(5)
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
MDLabel:
font_size: dp(12)
text: '123'
MDLabel:
font_size: dp(22)
text: '456'
Woops, looks like a simple mistake. Your indentation on KV Lang is incorrect. You didn't nest your labels into BoxLayout correctly.
AnchorLayout:
anchor_y: 'top'
BoxLayout:
orientation: 'vertical'
size_hint: 0.95, 0.5
padding: [0, 0, 0, 0]
spacing: dp(5)
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
MDLabel:
font_size: dp(12)
text: '123'
MDLabel:
font_size: dp(22)
text: '456'"""

kivy Error when trying to add a button on gridlayot in a different class

My app wants to make a list from the strings typed in the TextInput field and show them in the gridlayout in the middle of the window after pressing the button "Buscar". I'm sharing variables and functions between classes but when i try to add a new button with the TextInput.text inside the gridlayout shows the error message:
"AttributeError: 'kivy.properties.ObjectProperty' object has no attribute 'add_widget'"
Thank you
The interface looks like this
This is my .py file
from kivy.app import App
from kivy.uix.button import Button
from kivy.properties import ObjectProperty, NumericProperty, StringProperty
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.scrollview import ScrollView
class Lista(ScrollView):
lista_repuestos = ObjectProperty()
class CustomWidget(FloatLayout):
campo_de_busqueda_text_input = ObjectProperty()
repuesto = StringProperty('')
def submit_repuesto(self):
self.repuesto = self.campo_de_busqueda_text_input.text
Lista.lista_repuestos.add_widget(Button(text=self.repuesto))
class CustomWidgetApp(App):
def build(self):
return CustomWidget()
if __name__ == "__main__":
CustomWidgetApp().run()
this is my .kv file
CustomWidget:
<CustomWidget>:
campo_de_busqueda_text_input: campodebusqueda
TextInput:
id: campodebusqueda
size_hint: .7, .1
pos_hint: {"x": .15, "y": .85}
Button:
on_release: root.submit_repuesto()
size_hint: .1, .1
pos_hint: {"x": .85, "y": .85}
text: "Buscar"
Label:
size_hint: .15, .05
pos_hint: {"x": .05, "y": .15}
text: "DescripciĆ³n"
text_size: self.size
halign: "left"
Label:
size_hint: .15, .05
pos_hint: {"x": .05, "y": .10}
text: "Referencia"
text_size: self.size
halign: "left"
Label:
size_hint: .15, .05
pos_hint: {"x": .05, "y": .05}
text: "Cantidad"
text_size: self.size
halign: "left"
<Lista>:
lista_repuestos: listarepuestos
GridLayout:
id: listarepuestos
size_hint: .7, .6
pos_hint: {"x": .15, "y": .25}
cols: 1
row_default_height: 50
row_force_default: True
padding: 5
height: self.minimum_height
size_hint_y: None
Your line in the CustomWidget:
Lista.lista_repuestos.add_widget(Button(text=self.repuesto))
should reference an instance of Lista, not the class itself.

Categories