且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Python 中将特定文本设置为 Entry?

更新时间:2022-05-24 22:36:22

条目小部件没有 set 方法.如果您正在阅读的某些文档表明确实如此,您可能需要联系作者以告诉他们他们是正确的.

Entry widgets don't have a set method. If there is some documentation you are reading that says it does, you might want to contact the author to tell them they are correct.

对于条目小部件,您有两种选择.一,如果你有一个 textvariable 关联,你可以在 textvariable 上调用 set .这将导致与 textvariable 关联的任何小部件被更新.其次,如果没有 textvariable,您可以使用 insertdelete 方法来替换小部件中的内容.

For an entry widget you have two choices. One, if you have a textvariable associated, you can call set on the textvariable. This will cause any widgets associated with the textvariable to be updated. Second, without a textvariable you can use the insert and delete methods to replace what is in the widget.

这是后者的一个例子:

fahrenheitEntry.delete(0, "end")
fahrenheitEntry.insert(0, cgrade)