Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_entry_character_limit.py
- from Tkinter import *
- limit = 5
- Window = Tk()
- Window.geometry("200x200+50+50") # heightxwidth+x+y
- mainPanel = Canvas(Window, width = 200, height = 200) # main screen
- mainPanel.pack()
- entry_text = StringVar() # the text in your entry
- entry_widget = Entry(mainPanel, width = 20, textvariable = entry_text) # the entry
- mainPanel.create_window(100, 100, window = entry_widget)
- def character_limit(entry_text):
- if len(entry_text.get()) > 0:
- entry_text.set(entry_text.get()[:limit]) # char limit
- entry_text.trace("w", lambda *args: character_limit(entry_text))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement