tkinter Entry() 不返回字符串
我有几个用 tk 制作的输入框: Entry()
我需要将用户输入的内容放入变量中,我这样做(正如我在网上找到的):
window = Tk()
#make entry and turn it into stringvar
entry1string = tk.StringVar
entry_1 = Entry(window,textvariable=entry1string)
#retrieve it into a variable
retrieved = entry1string.get()
这给出了以下错误:
AttributeError: 'str' object has no attribute 'get'
如何将用户输入到输入框中的字符串/值获取到变量中?该代码似乎就是我找到的每个示例的样子,我不明白为什么它会给我这个错误。
I have several entry boxes made with tk: Entry()
I need to put what the user enters into a variable, which I do as such (as I have found online):
window = Tk()
#make entry and turn it into stringvar
entry1string = tk.StringVar
entry_1 = Entry(window,textvariable=entry1string)
#retrieve it into a variable
retrieved = entry1string.get()
This gives the following error:
AttributeError: 'str' object has no attribute 'get'
How do I get the string/value entered into the entry box by the user into a variable? The code seems to be just how every example I've found is, I don't see why it's giving me that error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅此处了解Tkinter 中的条目小部件。
您可以做的是创建一个按钮,单击该按钮后,将检索在“条目”框中输入的数据。
单击按钮时需要调用一个函数。您可以在命令行中打印数据,甚至可以在 GUI 窗口上输出,这是您的选择。
阅读文档了解更多信息。
Refer here to know about Entry widgets in Tkinter.
What you can do is create a button, on which upon clicking, the data entered in the Entry box will be retrieved.
There needs to be a function to call when the button is clicked. you can print the data in the command line or even output on the GUI window, that's your choice.
Read the documentation to know more.