Kivy TypeError - 在Try / Except子句中不能调用Label对象

时间:2017-06-15 22:22:43

标签: python python-3.x user-interface kivy

所以我试图创建一个try / except块来运行这段代码,他们应该能够点击打印出答案的弹出窗口,然后按计算按钮重新打开它。但是,当我第二次按下计算按钮时,它会给我

TypeError: 'Label' object is not callable

我会把代码放在下面:

class TabSys(TabbedPanel):
savedfiles_hydraulus = []
def calculate_psc_clicked(self, Cp_text, P_text, lhv_text):
    global psychrometric_constant
    #when they click the button which is id'd as "calculate_psc," this function
    #will pull the values and perform the calculations
    try:
        psychrometric_constant = (float(Cp_text)*float(P_text))/(float(lhv_text)*float(2.26))
        self.psc_answer()
    except ValueError:
        """Needs a popup for wrong results"""


#the popups print out the answers and offer the user an option to save or dismiss the window
def psc_answer(self):
    global Flag
    Flag = False

    #Layout
    popupscreen = FloatLayout()
    self.psc_notes_label = Label(text = "Psychrometric constant: (Cp*P)/(λ*MWr)", pos_hint = {"center_x": 0.5, "center_y": 0.7})
    self.psc_answer = Label(text = str(psychrometric_constant), pos_hint = {"center_x": 0.5, "center_y": 0.4})
    popupscreen.add_widget(self.psc_notes_label)
    popupscreen.add_widget(self.psc_answer)

    #Dismiss Window
    self.cancel_psc_answer = Button(text = "Cancel", pos_hint = {"center_x": .575, "center_y": .065}, size_hint = (.3, .2))
    self.cancel_psc_answer.bind(on_release = self.dismisspsc)
    popupscreen.add_widget(self.cancel_psc_answer)

    #Window Setup
    self.popup = Popup(title="Result", content = popupscreen,  size_hint=(.5, .5), size=(400, 400),
    separator_color = [217/255, 179/255, 255/255., .85])
    self.popup.open()

#Dismiss Function
def dismisspsc(self, *args):
    self.popup.dismiss()

不幸的是,它已经相当多了,但是我尽可能多地削减了它。如果有人需要,我现在可以将pastebin与整个代码链接起来。

我认为问题可能就在于行

try:
    psychrometric_constant = (float(CP_text)*float(P_text))/(float(lhv_text)*float(2.26))

位于try / except块中,可以更好地在psc_answer的函数内部提供。

非常感谢:)

1 个答案:

答案 0 :(得分:0)

我找到了答案!如果有人遇到这个问题,可能是因为你在某个时候对一个函数使用了相同的名称作为一个函数。我将函数命名为psc_answer,标签为psc_answer。