Не передается текст между классами
Всем привет, помогите понять почему не передается текст между классами, программу писали для KIVY, но только через .PY файл, нужно добиться что-бы данные из "self.Product" и "self.Quantity" из класса "ScreenMain", при нажатии кнопки "V", попадали в "self.lbl" и "self.lbl2" класса "ScreenSecond", но этого почему то не происходит. Помогите, пожалуйста)
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.gridlayout import GridLayout
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.lang import Builder
class ScreenMain(Screen):
def __init__ (self, **kwargs):
super().__init__(**kwargs)
## Создание кнопок "Далее" и "Назад"
self.main_widget = Widget()
self.main_widget.add_widget(Button(text='Далее', on_press=self._on_press_button_second_screen, pos = [200, 0], size=(100, 50)))
## Создаем первый экземпляр Layout
self.main_layout = GridLayout(cols=1, row_force_default=True, row_default_height=45,padding = [30, 0], spacing = 3)
self.gl_1 = GridLayout(cols=4)
self.Product = (TextInput(size_hint=[.7, .05], font_size=24, halign='left'))
self.gl_1.add_widget(self.Product)
self.Quantity = (TextInput(font_size=24, halign = 'center', size_hint=[None, .1], size=[50, 45]))
self.gl_1.add_widget(self.Quantity)
self.gl_1.add_widget(Button(text='V', on_press = self.btn_press_ok, size_hint=[None, .1], size=[50, 45]))
self.gl_1.add_widget(Button(text='X', size_hint=[None, .1], size=[50, 45]))
self.main_layout.add_widget(self.main_widget)
self.main_layout.add_widget(self.gl_1)
self.add_widget(self.main_layout)
self.a = ''
self.b = ''
self.update_data()
def update_data(self):
self.a = self.Product.text
self.b = self.Quantity.text
return self
def btn_press_ok(self, instance):
self.a = self.Product.text
self.b = self.Quantity.text
self.update_data()
## Создаем кнопку для добавления дополнительного Layout
self.gl_1 = GridLayout(cols=4)
self.Product = (TextInput(size_hint=[.7, .05], font_size=24, halign='left'))
self.gl_1.add_widget(self.Product)
self.Quantity = (TextInput(font_size=24, halign='center', size_hint=[None, 0.1], size=[50, 45]))
self.gl_1.add_widget(self.Quantity)
self.gl_1.add_widget(Button(text='V', on_press = self.btn_press_ok, size_hint=[None, 0.1], size=[50, 45]))
self.gl_1.add_widget(Button(text='X', size_hint=[None, .1], size=[50, 45]))
self.main_layout.add_widget(self.gl_1)
ScreenSecond().update_data_second()
def btn_press_del(self, instance):
self.main_layout.remove_widget(self.gl_1)
def _on_press_button_second_screen(self, *args):
## Создаем функцию кнопки Далее
self.manager.transition.direction = 'left'
self.manager.current = 'second_screen'
X1_Screen = ScreenMain().update_data()
class ScreenSecond(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.a1 = X1_Screen.a
self.b1 = X1_Screen.b
## Создаем кнопку Назад
self.main_widget = Widget()
self.main_widget.add_widget(Button(text='Назад', on_press=self._on_press_button_main_screen, pos=[0, 0], size=(100, 50)))
## Создаем экземпляр Label для отображение введенных данных с первой страницы
self.main_layout = GridLayout(cols=1, row_force_default=True, row_default_height=45, padding=[30, 0], spacing=3)
gl_2 = GridLayout(cols=3)
self.lbl = Label(text = str(self.a1), font_size = 15)
gl_2.add_widget(self.lbl)
self.lbl2 = Label(text = str(self.b1), font_size = 15)
gl_2.add_widget(self.lbl2)
self.main_layout.add_widget(self.main_widget)
self.main_layout.add_widget(gl_2)
self.add_widget(self.main_layout)
def update_data_second(self):
self.a1 = X1_Screen.a
self.b1 = X1_Screen.b
def _on_press_button_main_screen(self, *args):
## Создаем функцию кнопки Назад
self.manager.transition.direction = 'right'
self.manager.current = 'main_screen'
X2_Screen = ScreenSecond()
class MyApp(App):
def build(self):
sm = ScreenManager()
sm.add_widget(ScreenMain(name='main_screen'))
sm.add_widget(ScreenSecond(name='second_screen'))
return sm
if __name__ == '__main__':
MyApp().run()