How to prevent entering negative numbers in Kivymd MDTextField

Question:

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

Asked By: Edem

||

Answers:

You can use try/ except:

try: 
  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.