Я новичок в этом, поэтому могу представить, что это выглядит ужасно. Мои проблемы начинаются со строки 43. Я взял кусочки другого кода, который нашел, чтобы начать обучение. Мне не удалось найти ответы на kivy, например, около python.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
Builder.load_string("""
<Calc>:
# This are attributes of the class Calc now
a: _a
b: _b
c: _c
d: _d
e: _e
result: _result
AnchorLayout:
anchor_x: 'center'
anchor_y: 'top'
ScreenManager:
size_hint: 1, .9
id: _screen_manager
Screen:
name: 'screen1'
GridLayout:
cols:1
Label:
text: 'Grats'
TextInput:
id: _a
Label:
text: 'Alcohol Sales'
TextInput:
id: _b
Label:
text: 'Food Sales'
TextInput:
id: _c
Label:
id: _result
TextInput:
id: _d
text: '0.06'
TextInput:
id: _e
text: '0.05'
Button:
text: 'sum'
# You can do the opertion directly
on_press: _result.text = int(_a.text) - (str(int(root.b)) * int(float(root.d.text)) + str(int(root.c)) * int(float(root.e.text))
Button:
text: 'product'
# Or you can call a method from the root class (instance of calc)
on_press: root.product(*args)
Screen:
name: 'screen2'
Label:
text: 'The second screen'
AnchorLayout:
anchor_x: 'center'
anchor_y: 'bottom'
BoxLayout:
orientation: 'horizontal'
size_hint: 1, .1
Button:
text: 'Go to Screen 1'
on_press: _screen_manager.current = 'screen1'
Button:
text: 'Go to Screen 2'
on_press: _screen_manager.current = 'screen2'""")
class Calc(FloatLayout):
# define the multiplication of a function
def product(self, instance):
# self.result, self.a and self.b where defined explicitely in the kv
self.result.text = int(_a.text) - (str(int(self.b.text) * int(self.d.text)))
class TestApp(App):
def build(self):
return Calc()
if __name__ == '__main__':
TestApp().run()
У меня есть похожее приложение, работающее только с python, которое дает чаевые. Я хотел бы добавить к этому GUI, но не могу заставить математическую часть работать.