获取 Tkinter Entry 小部件的内容
问题描述:
我正在创建一个应用程序,我想使用在 GUI Entry 小部件中输入的值.
I am creating an application and I want to use the entered values in the GUI Entry widget.
如何从 Tkinter Entry 小部件获取输入的输入?
How do I get the entered input from a Tkinter Entry widget?
root = Tk()
...
entry = Entry(root)
entry.pack()
root.mainloop()
答
你需要做两件事:保持对小部件的引用,然后使用 get()
方法来获取字符串.
You need to do two things: keep a reference to the widget, and then use the get()
method to get the string.
这是一个例子:
self.entry = Entry(...)
...
print("the text is", self.entry.get())