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

    id: z1_m
    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

Asked By: Edem



You can use try/ except:

  x = int(input())
  assert x > 0 
except AssertionError :
  print("Only positives are allowed")
Answered By: God Is One
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.