here2share

# Tk_entry_limit.py

Dec 26th, 2021 (edited)
1,249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. # Tk_entry_limit.py
  2.  
  3. import tkinter
  4.  
  5. root = tkinter.Tk()
  6. myvar = tkinter.StringVar()
  7. myvar.set('')
  8. mywidget = tkinter.Entry(root,textvariable=myvar,width=30)
  9. mywidget.pack()
  10.  
  11. top2rows = '1234567890qwertyuiopQWERTYUIOP()\|_+-='
  12. def instant_relay(*t):
  13.     inStr = myvar.get()
  14.     if inStr:
  15.         if (inStr[-1] not in top2rows) or len(inStr) > 6:
  16.             print(f"Key Entry Rejected... [{inStr[-1:]}]")
  17.             inStr = inStr[:-1]
  18.     myvar.set(inStr)
  19.     mywidget.update_idletasks()
  20.  
  21. myvar.trace('w',instant_relay)
  22.  
  23. root.mainloop()
Add Comment
Please, Sign In to add comment