Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_entry_limit.py
- import tkinter
- root = tkinter.Tk()
- myvar = tkinter.StringVar()
- myvar.set('')
- mywidget = tkinter.Entry(root,textvariable=myvar,width=30)
- mywidget.pack()
- top2rows = '1234567890qwertyuiopQWERTYUIOP()\|_+-='
- def instant_relay(*t):
- inStr = myvar.get()
- if inStr:
- if (inStr[-1] not in top2rows) or len(inStr) > 6:
- print(f"Key Entry Rejected... [{inStr[-1:]}]")
- inStr = inStr[:-1]
- myvar.set(inStr)
- mywidget.update_idletasks()
- myvar.trace('w',instant_relay)
- root.mainloop()
Add Comment
Please, Sign In to add comment