self.text = Text(width=200, height=100, fg='black', wrap=WORD, yscrollcommand=scrollbar.set)
self.text.pack()
textLen = str(len(self.text.get(1.0)))
self.wordCounter = tk.Label(toolbarBottom, justify="left" , bg="#d7d8e0", text="Слов в тексте: " + textLen)
self.wordCounter.pack()
def count():
textLen = str(len(text.get(1.0, END)))
wordCounter["text"] = "Символов в тексте: " + textLen
text.bind("<Key>", lambda e: count())
def toolbar(self):
.....
self.wordCounter = tk.Label(toolbarBottom, justify="left", bg="#d7d8e0", text="Символов в тексте: 0")
self.wordCounter.pack()
self.text.bind('<KeyPress>', self.on_textfield_update)
self.text.bind('<KeyRelease>', self.on_textfield_update)
.....
def on_textfield_update(self, event):
symbols = len(self.text.get('1.0', END).strip())
self.wordCounter['text'] = 'Символов в тексте: {}'.format(symbols)