简体   繁体   中英

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". 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: 
  x = int(input())
  assert x > 0 
except AssertionError :
  print("Only positives are allowed")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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