0

I want field 1 to fill only integers and field 2 to be float.

Please help me find a solution of the problem.

import tkinter as tk

root = tk.Tk()
root.geometry("410x360")  
label = tk.Label(text='integer')
label.grid(row=1,column=1)
label = tk.Label(text='float')
label.grid(row=2,column=1)

integer = tk.Entry(root)
integer.grid(row=1,column=2)

float_ = tk.Entry(root)
float_.grid(row=2,column=2)


root.mainloop()
martineau
  • 119,623
  • 25
  • 170
  • 301
HOW TO
  • 5
  • 2
  • One way is by adding custom validation to the `Entry` widgets — see [Adding validation to an `Entry` widget](https://tkdocs.com/shipman/entry-validation.html). – martineau Jul 30 '22 at 14:48

1 Answers1

0

Install this package, it does the job. tkvalidate

then import:

import floatvalidate \\for validating float only entry
import intvalidate \\for validating int only entry

add these lines under respective Entry:

floatvalidate.float_validate(float_, from_=0, to=99)

intvalidate.int_validate(integer, from_=0, to=99)

change range (from and to) as per your need.