如何一次创建多个入口小部件?

How to create multiple entry widgets at once?

我正在使用 python3 和 tkinter 将数据输入表单作为 GUI 的一部分。 我创建了 10 个数据输入小部件,如下所示:

enter1 = Entry(self,textvariable = shots1)
enter1.place(x=1000, y=200)
enter2 = Entry(self, textvariable = shots2)
enter2.place(x=1000, y=250)
enter3 = Entry(self, textvariable = shots3)
enter3.place(x=1000, y=300)
enter4 = Entry(self, textvariable = shots4)
enter4.place(x=1000, y=350)

我想知道是否有更有效的方法 - 也许使用 for 循环或 class - 我可以在其中一起创建所有这些?

使用循环。小部件与任何其他类型的对象没有什么不同。

entries =[]
for i in range(5):
    entries.append(Entry(self, ...))

您几乎不需要使用文本变量,所以我建议您不要使用它们,除非您需要它们的一些独特功能。您可能还应该使用 packgrid 而不是 placeplace 通常只适用于非常特殊的边缘情况。