python input输入的数据类型_在接受Inpu之前,在输入时验证Kivy TextInput是否为数据类型Integer...

详情请参阅说明和示例。

TextInput-输入过滤器

使用input_filter: 'float'。使用input_filter,您不必检查方法中的“init”或“float”。input_filter

Filters the input according to the specified mode, if not None. If

None, no filtering is applied.

input_filter is an ObjectProperty and defaults to None. Can be one of

None, ‘int’ (string), or ‘float’ (string), or a callable. If it is

‘int’, it will only accept numbers. If it is ‘float’ it will also

accept a single period. Finally, if it is a callable it will be called

with two parameters; the string to be added and a bool indicating

whether the string is a result of undo (True). The callable should

return a new substring that will be used instead.

kv文件

定义了两个根

在kv文件中,为同一根小部件定义了根规则AddKalibrasieForm:和类规则:。因为您没有使用def build()方法,所以请删除kv文件中的类规则:。

文本输入-音量框

添加以下内容:multiline: False # disable multiline

hint_text: "Slegs nommers" # Numbers only

input_filter: "float"

Python代码class AddKalibrasieForm(BoxLayout):

calculated_results = ObjectProperty(None)

val_lewerha = ObjectProperty(None)

def convert_calvariables(self):

if len(self.val_lewerha.text) > 0: # if text is not empty

print(format(self.val_lewerha.text))

else:

print("Error: Empty string")To declare properties, you must declare them at the class level.

示例

在主.py在

^{pr2}$

在校准.kv在#:kivy 1.11.0

AddKalibrasieForm: # root rule

orientation: "vertical"

val_lewerha: volha_box

calculated_results: calculated_results_table

BoxLayout:

height: "40dp"

size_hint_y: None

Label:

text: "Lewering per ha"

size_hint_x: 25

TextInput:

id: volha_box # TextInput object name

size_hint_x: 50

hint_text: "Slegs nommers"

multiline: False

input_filter: "float"

Label:

text: "liter"

size_hint_x: 25

text_size: self.size

halign: "left"

BoxLayout:

height: "60dp"

size_hint_y: None

Label:

size_hint_x: 35

Button:

text: "Bereken"

size_hint_x: 30

on_press: root.convert_calvariables() # method called on_press

Label:

size_hint_x: 35

ListView:

id: calculated_results_table

table_items: []

输出

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值