I am trying to add limitation on an Entry widget, like only 11 digits are allowed to be entered. I had tried this:
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox
root=tk.Tk()
string=tk.StringVar()
def limit(string):
if len(string.get())>11:
messagebox.showinfo('invalid input (should be 11 digits')
label=tk.Label(root,text="Phone Number:",font=20,bg="#33BEFF")
label.pack()
phno=ttk.Entry(root,textvariable=string,text="",command=limit)
phno.pack()
root.mainloop()
I want that only 11 digits should be entered in an Entry.