python - 如何在我的 python 计算器上制作平方根按钮(我是初学者)
问题描述
def btnSquareRoot(self):
result = False
current = math.sqrt(text_Input)
text_Input.set(current)
这是我尝试使用的代码,但我不能,因为text_Input
它是一个字符串 var 我是初学者,这就是为什么对我来说很难做到这一点,但我的想法是以某种方式转换它,但我不知道怎么做
解决方案
要将字符串转换为浮点数,您可以按照以下方式使用浮点函数:
def btnSquareRoot(self):
result = False
current = math.sqrt(float(text_Input))
text_Input.set(current)
推荐阅读
- powershell - 使用 WinRM 时出现 PSRemotingTransportException - IIS Web 应用部署
- rust - 如何处理来自 actix-multipart 数据的文件而不将其保存到磁盘
- node.js - 无法从本地存储中检索数据(Angular 8)
- mysql - 无法将 VPS 上的 NodeJS 连接到另一个主机上的 MySQL
- r - 如果字符串包含任何单词列表,R每行返回真或假
- html - 如何模糊除一个元素之外的所有内容
- daml - 与 GHCI 等效的 daml repl
- spring-boot - 为什么在 SpringBoot 测试中使用 @AutoConfigureMockMvc 时总是出现 404?
- vue.js - 了解 Nuxt.js 中的状态和吸气剂:吸气剂不起作用
- openshift - 如何使用 Telegraf 从 Openshift 获取普罗米修斯指标?