我如何获取用户的输入并将答案显示到标签中,例如在 tkinter 中?

发布于 2025-01-16 22:29:20 字数 161 浏览 3 评论 0原文

我正在尝试使用 Tkinter 创建一个基本计算器。

基本上,用户输入圆的半径,然后它应该打印出圆的直径、周长和面积。

我一直在尝试 Entry().get() 但我还没有发现任何关于我的问题的信息。

多谢。

I'm trying to create a basic calculator with Tkinter.

Basically the user types in the radius of a circle and then it should print out the diameter, circumference and the area of the circle.

I've been experimenting with Entry() and .get() but yeah i haven't found out anything yet about my problem.

Thanks a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空袭的梦i 2025-01-23 22:29:20

我认为您正在寻找这样的东西:

radius = tk.DoubleVar()
radius_entry = ttk.Entry(root, textvariable=radius)
radius_entry.pack()

然后,如果您运行radius.get(),您将获得当前条目。

您还可以使用跟踪来跟踪输入何时发生变化: https://www. geeksforgeeks.org/tracing-tkinter-variables-in-python/

我建议您查看学习 tkinter 的在线教程以获取更多信息。当我开始 tkinter 时,这个教程对我帮助很大: https://www.pythontutorial.net/tkinter/

I think you're looking for something like this:

radius = tk.DoubleVar()
radius_entry = ttk.Entry(root, textvariable=radius)
radius_entry.pack()

Then if you run radius.get() you get the current entry.

You can also track when the input changes with trace: https://www.geeksforgeeks.org/tracing-tkinter-variables-in-python/

I recommend taking a look at an online tutorial for learning tkinter to get more information. This tutorial helped me a lot when I started tkinter: https://www.pythontutorial.net/tkinter/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文