我如何从 python tkinter 条目中获取整数值?
所以我知道 python 中的条目是如何工作的,并且我在一些项目中对其进行了编码。但在一个项目中,需要从用户输入的数字(number)值。但它给出了条目仅支持字符串数据的错误。你能解决这个问题吗?谢谢。
so I know how entry in python works and i coded it in some projects. but in one project , there was need to get numeric ( number ) value from user in entry. but it gives the error that entry only supports string data. can you solve this problem ? thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需将其类型转换为整数即可。例如。这段代码对我有用:
You just need to typecast it into an integer. Eg. This code worked for me:
除此之外,您可以使用验证来确保您只能在条目中写入计算结果为整数的值:
可以找到有关条目验证的更多信息此处。
To add further to this, you can use validation to ensure that you can only write values that evaluate to an integer in your entry:
Some more info on Entry validation can be found here.