У меня есть объект «Полоска», который я хочу создать при нажатии кнопки. У меня есть несколько TextInputs и кнопка. Я хочу, чтобы кнопка могла получить все входные данные и сохранить их в объекте "Streak". Как бы я поступил так? Вот код .kv:
<ScreenOne>:
name: "one"
AnchorLayout:
anchor_x: 'left'
anchor_y: 'top'
Button:
on_release: app.root.current = "main"
text: "Back"
size: 50, 25
size_hint: None, None
font_size: 18
GridLayout:
cols:1
rows:6
Label:
text: "Action"
font_size: 18
size: 600, 50
size_hint: None, None
TextInput:
id: action_entry
multiline: False
size: 600, 28
size_hint: None, None
Label:
text: "Streak #"
size: 600, 50
size_hint: None, None
TextInput:
id: streak_entry
multiline: False
size_hint: None, None
size: 600, 28
Label:
size: 600, 50
size_hint: None, None
text: "Due every"
GridLayout:
cols:3
rows:2
Label:
text: "Day(s)"
size_hint: None, None
font_size: 18
Label:
text: "Hour(s)"
size_hint: None, None
font_size: 18
Label:
text: "Minute(s)"
size_hint: None, None
font_size: 18
TextInput:
id: day_entry
multiline: False
size_hint: None, None
size: 200, 28
TextInput:
id: hour_entry
multiline: False
size_hint: None, None
size: 200, 28
TextInput:
id: minute_entry
multiline: False
size_hint: None, None
size: 200, 28
AnchorLayout:
anchor_x: "right"
anchor_y: "bottom"
Button:
text: "Add"
size: 50, 25
size_hint: None, None
font_size: 18
on_press: Streak.create(instance)
Вот код .py:
class Streak():
def __init__(self, action, action_num, day, hour, minute):
self.action = action
self.action_num = action_num
self.day = day
self.hour = hour
self.minute = minute
class MainScreen(Screen):
pass
class ScreenOne(Screen):
pass
class ScreenManagement(ScreenManager):
pass
presentation = Builder.load_file("StreakStar.kv")
class MainApp(App):
def build(self): # build() returns an instance
return presentation
def create(self, instance):
streak = Streak(action_entry.text, streak_entry.text, day_entry.text,
hour_entry.text, minute_entry.text)
if __name__ == '__main__':
MainApp().run()
Когда я нажимаю кнопку, я получаю NameError: имя 'Streak' не определено