Как повторно обновить текст MDTextField, и MDRoundFlatButtn
На первый взгляд задача простая, но я уже три дня не могу ее решить. Мне нужно чтобы при нажатии на кнопку "Готово", переменные "a, b, c, d1, d2" принимали "Текущий текст" MDTextField`а. При первом запуске все отлично, но при втором результат тот же что и прежде. Помогите пожалуйста, вот часть кода нужная для определения проблемы:
PY
def go(self):
try:
self.a = self.ids.a.text
self.b = self.ids.b.text
self.c = self.ids.c.text
self.d1 = self.ids.d1.text
self.d2 = self.ids.d2.text
self.ids.a.hint_text = "a"
self.ids.b.hint_text = "b"
self.ids.c.hint_text = "c"
a = float(self.a)
b = float(self.b)
c = float(self.c)
d1 = self.d1
d2 = self.d2
if self.ids.d1.text == "-":
b = -b
if self.ids.d2.text == "-":
c = -c
D = (b ** 2) - 4 * a * (c)
if D < 0:
Kor = math.sqrt(abs(D))
Kor = -Kor
elif D > 0 or D == 0:
Kor = math.sqrt(D)
RKor = round(Kor, 2)
x1 = (-b + Kor) / (a * 2)
x2 = (-b - Kor) / (a * 2)
if not self.dialog:
self.dialog = MDDialog(
title = "Вывод",
text = f"{a} {b} {c} {d1} {d2}",
size_hint = [0.95, 1],
buttons = [
MDRaisedButton(
text = "Ok",
on_release = self.on_close
)
]
)
self.dialog.open()
except ValueError:
self.ids.a.hint_text = "Введите число!"
self.ids.b.hint_text = "Введите число!"
self.ids.c.hint_text = "Введите число!"
KV
BoxLayout:
orientation: "vertical"
padding: [20]
GridLayout:
cols: 2
spacing: 20
MDTextField:
id: a
text: ""
hint_text: "a"
MDRoundFlatButton:
id: d1
text: "+"
text_color: 1, 1, 1, 1
md_bg_color: 0, .7, .5, 1
font_size: 30
on_press: root.dia1()
MDTextField:
id: b
text: ""
hint_text: "b"
MDRoundFlatButton:
id: d2
text: "+"
text_color: 1, 1, 1, 1
md_bg_color: 0, .7, .5, 1
font_size: 30
on_press: root.dia2()
MDTextField:
id: c
text: ""
hint_text: "c"
MDRoundFlatButton:
id: zero
text: "= 0"
text_color: 1, 1, 1, 1
md_bg_color: 0, .7, .5, 1
font_size: 20
AnchorLayout:
anchor_x: "right"
anchor_y: "bottom"
MDRaisedButton:
id: go
text: "Готово"
md_bg_color: 0, .7, .5, 1
size_hint: [1, None]
on_press: root.go()
Буду очень благодарен!