【发布时间】:2015-12-28 12:34:45
【问题描述】:
我正在编写一个轻量级的网络文本应用程序,并且我正在尝试在 TKinter 文本小部件中显示当前字符数,该小部件用于编写要在网络文本中发送的消息。我现在的代码可以在下面看到,我正在使用python
root = Tk()
msgLabel = Label(text="Message")
msgLabel.grid(row=0, column=0)
msg = Text(width=40, height=4, wrap="word")
msg.grid(row=0, column=1, padx=10, pady=5)
#Try to display number of characters within message to user
charCount = Label(text="Character Count: "+str(len(meg.get("1.0", 'end-1c')))
charCount.grid(row=1, column=1, pady=5, padx=5)
root.mainloop()
我希望能够显示用户编写的消息中的字符数,因为每个网络文本有 160 个字符的限制。是否可以显示当前字符长度,随着文本的插入和删除而更新?在此先感谢
【问题讨论】:
标签: python user-interface text tkinter widget