获取 Tkinter Entry 小部件的内容 [英] Get contents of a Tkinter Entry widget

查看:67
本文介绍了获取 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())

这篇关于获取 Tkinter Entry 小部件的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆