简体   繁体   English

如何防止在 Kivymd MDTextField 中输入负数

[英]How to prevent entering negative numbers in Kivymd MDTextField

In MDTextField, there is a restriction on entering only numbers, this is input_filter: "float", "int".在MDTextField中,有一个只能输入数字的限制,这个是input_filter: "float", "int"。 But you can enter negative numbers但是你可以输入负数

MDTextField:
    id: z1_m
    text:""
    hint_text: "z1"
    helper_text: "Число зубьев шестерни"                        
    helper_text_mode: "on_focus"
    input_filter: "float"                                               
    on_text_validate: app.prochnjst()

Expected that when the user enters a minus sign, nothing happens预期当用户输入减号时,什么也不会发生

You can use try/ except:你可以使用 try/ 除了:

try: 
  x = int(input())
  assert x > 0 
except AssertionError :
  print("Only positives are allowed")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM