[英]How to prevent entering negative numbers in Kivymd MDTextField
在MDTextField中,有一個只能輸入數字的限制,這個是input_filter: "float", "int"。 但是你可以輸入負數
MDTextField:
id: z1_m
text:""
hint_text: "z1"
helper_text: "Число зубьев шестерни"
helper_text_mode: "on_focus"
input_filter: "float"
on_text_validate: app.prochnjst()
預期當用戶輸入減號時,什么也不會發生
你可以使用 try/ 除了:
try:
x = int(input())
assert x > 0
except AssertionError :
print("Only positives are allowed")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.