Advertisement
here2share

# Tk_entry_character_limit.py

May 23rd, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. # Tk_entry_character_limit.py
  2.  
  3. from Tkinter import *
  4.  
  5. limit = 5
  6.  
  7. Window = Tk()
  8. Window.geometry("200x200+50+50") # heightxwidth+x+y
  9.  
  10. mainPanel = Canvas(Window, width = 200, height = 200) # main screen
  11. mainPanel.pack()
  12.  
  13. entry_text = StringVar() # the text in  your entry
  14. entry_widget = Entry(mainPanel, width = 20, textvariable = entry_text) # the entry
  15. mainPanel.create_window(100, 100, window = entry_widget)
  16.  
  17. def character_limit(entry_text):
  18.     if len(entry_text.get()) > 0:
  19.         entry_text.set(entry_text.get()[:limit]) # char limit
  20.  
  21. entry_text.trace("w", lambda *args: character_limit(entry_text))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement