Validation functions for tkinter Entry widgets that only allow integers or floats
Project description
tkvalidate
Validation functions that only allow integers or floats for tkinter Entry
widgets
The validate functions are called with an Entry
widget as an argument. The following code will validate an Entry
so
only integers in the range -5 to 5 may be entered.
import tkinter as tk
root = tk.Tk()
widget = tk.Entry(root, justify=tk.CENTER)
widget.pack(padx=10, pady=10)
int_validate(widget, from_=-5, to=5)
root.mainloop()
This works on any subclass of Entry
. For a ttk.Spinbox
it can take the limits directly from the Spinbox
. The
following code accomplishes the same as the previous but with a Spinbox
.
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
widget = ttk.Spinbox(root, justify=tk.CENTER, from_=-5, to=5)
widget.pack(padx=10, pady=10)
int_validate(widget)
root.mainloop()
For validating floating points instead of integers, simply use float_validate
instead.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tkvalidate-1.0.1.tar.gz
(3.1 kB
view hashes)
Built Distribution
Close
Hashes for tkvalidate-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 781dbf52a3b8426ad9a5a0652fc1a0e47a51cccd85576aa90e20f746fdf73bff |
|
MD5 | 1ddbe9dd26cfaf00efa6dccac4210dd8 |
|
BLAKE2b-256 | 215f9e0580621aa5932418d02ce1b6c8ef9b40a6eca845106bc787894ec8d54f |