首页 > 解决方案 > 如何在我的 python 计算器上制作平方根按钮(我是初学者)

问题描述

def btnSquareRoot(self):
   result = False
   current = math.sqrt(text_Input)
   text_Input.set(current)

这是我尝试使用的代码,但我不能,因为text_Input它是一个字符串 var 我是初学者,这就是为什么对我来说很难做到这一点,但我的想法是以某种方式转换它,但我不知道怎么做

标签: pythoncalculator

解决方案


要将字符串转换为浮点数,您可以按照以下方式使用浮点函数:

def btnSquareRoot(self): 
        result = False 
        current = math.sqrt(float(text_Input)) 
        text_Input.set(current)

推荐阅读