What's the difference between Entry() and Text()?

十年热恋 提交于 2020-06-28 05:45:12

问题


What's the difference between tkinter's Entry() and Text() functions?

Couldn't find anything online, so after figuring it out, wanted to make it available online for others.


回答1:


Entry() allows one line of input:

Whereas, Text() allows multi-line inputs:




回答2:


Any documentation on Tkinter will tell you the answer. In fact, it's usually literally the very first thing it will tell you.


Entry in the Tkinter Book starts off with:

The Entry widget is a standard Tkinter widget used to enter or display a single line of text.

When to use the Entry Widget

The entry widget is used to enter text strings. This widget allows the user to enter one line of text, in a single font.

To enter multiple lines of text, use the Text widget.


Entry in the Tkinter reference starts with:

The purpose of an Entry widget is to let the user see and modify a single line of text.

  • If you want to display multiple lines of text that can be edited, see Section 24, “The Text widget”.

And so on.




回答3:


The Entry widget has validation commands (ie, possibility to have only lowercase, only digits etc). This needs some workaround to make work in Text widgets.



来源:https://stackoverflow.com/questions/50194711/whats-the-difference-between-entry-and-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!