Найти - Пользователи
Полная версия: tkinter.Entry. Ограничить количество вводимых символов.
Начало » GUI » tkinter.Entry. Ограничить количество вводимых символов.
1
plustilino
Требуется, чтобы в текстовую строку нельзя было ввести более одного символа. В документации не могу найти соответствующего свойства.
зы. Свойство width просто делает поле шириной в один символ, но не ограничивает ввод пользователя.
sp3
from Tkinter import *


root = Tk()

entr = Entry(root)
entr.pack()

def foo(e):
s = entr.get().strip()
s = s[-1] if s else ''
entr.delete ('0',END)
entr.insert(INSERT,s)
print e.char

entr.bind('<KeyRelease>',foo)


entr2 = Entry(root)
entr2.pack()

def foo2(e):
entr2.delete ('0',END)
print e.char

entr2.bind('<KeyPress>',foo2)



root.mainloop()
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB