-
Notifications
You must be signed in to change notification settings - Fork 7
/
utils.py
42 lines (32 loc) · 862 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def check_integer_format(text: str) -> bool:
"""
Check that the text is a positive integer
:param text: Text entered by the user in a tk.Entry widget
:return:
"""
if text == "":
return True
if all(x in "0123456789" for x in text):
try:
int(text)
return True
except ValueError:
return False
else:
return False
def check_float_format(text: str) -> bool:
"""
Check that the text is a positive floating number
:param text: Text entered by the user in a tk.Entry widget
:return:
"""
if text == "":
return True
if all(x in "0123456789." for x in text) and text.count(".") <= 1:
try:
float(text)
return True
except ValueError:
return False
else:
return False