Allow Decimal
A validation function to allow only decimal numbers.
- validation
- decimals
Code
from tkinter import Tk, Entry
def allow_decimal(action, value):
if action == "1":
if value == "":
return True
try:
float(value)
return True
except ValueError:
return False
return TrueUsage
root = Tk()
root.geometry("200x200")
reg = root.register(allow_decimal)
Entry(root, validate="key", validatecommand=(reg, "%d", "%P")).pack()
root.mainloop()