I'm so deeply stuck in this!!! I tried through hours of frustration to get this little thing done... Every help would be so kind and relieving. So here's my problem:
I know there's a bit of code, but the hole question turns just about two classes...
In the class Datum, I want a Label.
In the class Alledaten, I want a TextInput.
Now I want that TextInput to bind on_text_validate to update my Labels text.
I know how that works within the same class... (its pretty simple) but not in two different classes
'''
from kivy.app import App
from kivy.core.window import Window
from kivy.metrics import dp, sp
from kivy.properties import StringProperty, ObjectProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
from kivy.uix.textinput import TextInput
from wochenplaner_script import CodefuerWochenplaner_ausgeglichen as CW
Builder.load_file("kivy.kv")
Window.clearcolor = (1, 1, .5, .5)
# 1. File Managing -------------------------------
class Wochenplan(App):
def build(self):
# Designate .kv design file
# Builder.load_file("kivy.kv")
sm = ScreenManager()
sm.add_widget(Maininterface(name="screen_maininterface"))
sm.current = "screen_maininterface"
return sm
class Screenmanager(ScreenManager):
pass
# 2. Code ----------------------------------------
class Zeitplanprotag(GridLayout):
def __init__(self, **kwargs):
super(Zeitplanprotag, self).__init__(**kwargs)
y = Window.system_size[1]
for i in range(1, 16, 1):
buttonleft = Button(text=f'{i} left', size_hint=(.5, None), height=y * 0.1, halign="left", valign="middle")
buttonright = Button(text=f'{i} right', size_hint=(1, None), height=y * 0.1, halign="left", valign="middle")
self.add_widget(buttonleft)
self.add_widget(buttonright)
class Wochentage(BoxLayout):
def __init__(self, **kwargs):
super(Wochentage, self).__init__(**kwargs)
button = Button(size_hint=(.5, 1))
button.text = "Zeit"
button2 = Button(size_hint=(1, 1))
button2.text = "Plan"
self.add_widget(button)
self.add_widget(button2)
class Datum(BoxLayout):
text_input_str = StringProperty("tag")
def ooon_text_validate(self, widget):
self.text_input_str = widget.text
print(self.text_input_str)
# self.ids.label_am_arsch.text = self.text_input_str
self.ids.which_day.text = "harald"
# 2.2 Textinput -------------- <------ in here is my question
class Alledaten(BoxLayout):
# text_input_str = StringProperty("Tag 1")
def __init__(self, *args, **kwargs):
super(Alledaten, self).__init__(**kwargs)
input_ab_wann = TextInput(hint_text="Ab Tag: ",
hint_text_color=(0, 0, 0, 1),
background_color=(1, 1, 1, 1),
halign="center",
multiline=False)
# ids="input_ab_wann_id")
# input_ab_wann.bind(on_text_validate=Datum().ooon_text_validate) <----- **whyyy does this not go inside the function ooon_text_validate?**
def on_text(widget):
Datum().ooon_text_validate(widget) # <------ **but with this the terminal prints the input text, but doesn't change the Label text**
input_ab_wann.bind(on_text_validate=on_text)
self.add_widget(input_ab_wann)
# 3. Appearance ----------------------------------
class Spalteprotag(BoxLayout):
pass
# 4. Screens -------------------------------------
class Maininterface(Screen):
def float_in_int(self, float, **kwargs):
super(Maininterface).__init__(**kwargs)
de_int = float
return int(de_int)
# ----------------------------------
if __name__ == "__main__":
Wochenplan().run()
'''
and my kv file:
'''
<Screenmanager>:
Maininterface:
<Maininterface>:
# 1. Stufe
BoxLayout:
# 1. vBox -> 2. hBox -> 3. vBox -> 4. Grid 2 cols
orientation: "vertical"
size: root.width, root.height
# 1. Stufe
BoxLayout:
size_hint: (1, .15)
orientation: "horizontal"
Alledaten:
orientation: "vertical"
size_hint: (.3, 1)
Label:
text: "Wochenplan"
size_hint: (1, 1)
# texture_size: self.size
text_size: self.size
halign: "center"
valign: "middle"
markup: True
font_size: dp(20)
color: (0, 0, 0, 1)
Label:
text: ""
size_hint: (.3, .5)
Datum: # <------ in here is my Label
# 2. Stufe
BoxLayout:
orientation: "horizontal"
# 1 Spalte in Tabelle
Spalteprotag:
# 2 Spalte in Tabelle
# Spalteprotag:
<Spalteprotag>:
# -> BoxLayout
orientation: "vertical"
# size_hint: (.25, 1)
# 3. Stufe
Wochentage:
size_hint: (1, .1)
ScrollView:
do_scroll_x: False
do_scroll_y: True
Zeitplanprotag:
cols: 2
height: self.minimum_height
size_hint_y: None
# row_default_height: 100
row_force_default: False
# spacint: 10
<Zeitplanprotag>:
# 4. Stufe -> GridLayout
<Wochentage>:
<Datum>:
orientation: "horizontal"
size_hint: (1, .1)
TextInput:
id: zweite_input
hint_text: "this text input is just an example to show my question\n ->> the textinput above should work like that one!"
multiline: False
on_text_validate: root.text_input_str = self.text
Label: # <------ this is the label which causes problems
id: which_day
# text: root.text_input_str
text: root.text_input_str
# background_color: (0, 0, 0, 1)
color: (0, 0, 0, 1)
# size_hint: (1, 1)
<Alledaten>:
# TextInput:
# id: ab_tag_textin
# hint_text:"Ab Tag: "
# hint_text_color:(0, 0, 0, 1)
# background_color:(1, 1, 1, 1)
# halign:"center"
# multiline:False
# on_text_validate: Datum.ooon_text_validate = self.text <---- I tried it with an TextInput in the kv File but I did't know how to reference to another class...
if someone knows the solution via kv file im also very happy, but I want to now what I did wrong in my way to fix it via python file...
'''