【发布时间】:2020-03-10 09:38:02
【问题描述】:
是否可以在kivy中获得自动结果计算?我认为我有 3 个 TextInput 字段,当其中至少 2 个填写 3 时,我会得到结果。
我想到了类似的东西:
--------------
| 2 | --> TextInput 1
--------------
|result = 5 | --> TextInput 2
-------------
| 3 | ---> TextInput 3
--------------
Or
--------------
| result = 5 | --> TextInput 1
--------------
| 2 | --> TextInput 2
-------------
| 3 | ---> TextInput 3
--------------
输入至少 2 个数字后,结果应该会自动出现。
我的.py:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
class HomeScreen(Screen):
pass
class CalculatorHome(Screen):
pass
GUI = Builder.load_file("kv/my.kv")
class MainApp(App):
def build(self):
return GUI
def change_screen(self, screen_name, direction):
# Get the screen manager from the kv file
screen_manager = self.root.ids['screen_manager']
screen_manager.current = screen_name
screen_manager.transition.direction = direction
def clear_text(self, *args):
for ar in args:
ar.text = ''
MainApp().run()
使用 TextIput 计算.kv
<CalculatorHome>:
FloatLayout:
GridLayout:
rows:3
pos_hint: {"top": .8, "left": 1 }
size_hint: 1, .4
TextInput:
id: number1
multiline: False
TextInput:
id: number2
multiline: False
TextInput:
id: number3
multiline: False
GridLayout:
rows:1
pos_hint: {"top": .3, "left": 1 }
size_hint: 1, .1
Button:
text: "CLEAR"
on_press: app.clear_text(number1, number2, number3 )
【问题讨论】:
标签: python android kivy kivy-language