Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter Entry size limit
#2
You could test the length of the input and throw an error and remind that only 5 characters are allowed.



Quick example

import tkinter as tk
from tkinter import messagebox

def callback(field, arg):
    arg = arg.get()
    if len(arg) != 5:
        messagebox.showerror('Error', 'field must contain 5 characters')
        field.delete(0, tk.END)
    else:
        messagebox.showinfo('Correct', 'This field has 5 characters')

root = tk.Tk()
var = tk.StringVar()
contain = tk.LabelFrame(root, text='Some label text')
contain.pack(fill='both', expand=True)

field = tk.Entry(contain, textvariable=var, bd=2)
field.pack(fill='x', expand=True)

btn = tk.Button(contain, text='Submit', command=lambda: callback(field, var))
btn.pack(side='left', fill='x', pady=5)

root.mainloop()
vman44 likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
Tkinter Entry size limit - by vman44 - Dec-21-2022, 06:50 AM
RE: Tkinter Entry size limit - by menator01 - Dec-21-2022, 08:15 AM
RE: Tkinter Entry size limit - by deanhystad - Dec-22-2022, 12:08 AM
RE: Tkinter Entry size limit - by vman44 - Dec-22-2022, 06:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to open a popup window in tkinter with entry,label and button lunacy90 1 1,022 Sep-01-2023, 12:07 AM
Last Post: lunacy90
  Auto increament in Entry field. in tkinter GUI cybertooth 7 4,322 Sep-17-2021, 07:56 AM
Last Post: cybertooth
  How to rotate log and limit the size maiya 0 1,802 Aug-29-2020, 12:41 AM
Last Post: maiya
  How to limit the fie size in logging. maiya 2 7,501 Jul-29-2020, 06:49 AM
Last Post: maiya
  size of set vs size of dict zweb 0 2,209 Oct-11-2019, 01:32 AM
Last Post: zweb
  Restrict / Limit variable size mln4python 4 7,332 Aug-13-2019, 07:17 AM
Last Post: mln4python
  CSV file created is huge in size. How to reduce the size? pramoddsrb 0 10,572 Apr-26-2018, 12:38 AM
Last Post: pramoddsrb
  Help pulling tkinter Entry string data Raudert 8 10,220 Jan-12-2017, 11:49 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020