Skip to content

Latest commit

 

History

History
24 lines (17 loc) · 479 Bytes

allow-positive-integers.md

File metadata and controls

24 lines (17 loc) · 479 Bytes
title description author tags
Allow Positive Integers
A validation function to allow only positive integers.
Legopitstop
validation,positive,integers
from tkinter import Tk, Entry


def allow_positive_integers(value):
    return value.isdigit() and (value == "" or int(value) > 0)


# Usage:
root = Tk()
root.geometry("200x200")

reg = root.register(allow_positive_integers)
Entry(root, validate="key", validatecommand=(reg, "%P")).pack()

root.mainloop()