我正在编程一个货币转换器只是为了好玩,并学习更多关于python的东西。我试图通过“交换”按钮的按键功能来改变“计算”按钮的按键功能。我想改变这个方向。 代码如下: python文件:
class Waehrungsrechner(BoxLayout):
def swap_GBP(self,*args):
GBP_textleft = self.ids.GBP_textleft
GBP_textright = self.ids.GBP_textright
textleft = GBP_textleft.text
textright = GBP_textright.text
BTN_calc = self.ids.GBP_calc
direction = -1
if textleft == "Euro":
direction = 1
elif textleft == "Britisches Pfund":
direction = 2
if direction == 1:
GBP_textleft.text = "Britisches Pfund"
GBP_textright.text = "Euro"
BTN_calc.bind(on_press = Waehrungsrechner.calculate_GBP2())
direction = 2
elif direction == 2:
GBP_textleft.text = "Euro"
GBP_textright.text = "Britisches Pfund"
BTN_calc.bind(on_press = Waehrungsrechner.calculate_GBP1())
direction = 1
def calculate_GBP1(self,*args):
Input = self.ids.GBP_Input
label = self.ids.GBP_Ergebnis
access = True
try:
Eingabe = float(Input.text)
except:
label.text = "Error"
access = False
if access == True:
Ergebnis = "{0:.2f}".format(Eingabe*GBP_valuef)
label.text = str(Ergebnis)
def calculate_GBP2(self,*args):
Input = self.ids.GBP_Input
label = self.ids.GBP_Ergebnis
access = True
try:
Eingabe = float(Input.text)
except:
label.text = "Error"
access = False
if access == True:
Ergebnis = "{0:.2f}".format(Eingabe*(1/GBP_valuef))
label.text = str(Ergebnis)
class WaehrungsrechnerApp(App):
def build(self):
return Waehrungsrechner();
Waehrungsrechner1 = WaehrungsrechnerApp()
Waehrungsrechner1.run()
kv文件:
^{pr2}$它显示:calculate_GBP2()缺少1个必需的位置参数:“self”
它现在似乎同时使用了这两个函数,第一个函数覆盖了第二个函数的结果(添加print时)。我怎样才能解除这个功能与按钮的绑定?在
相关问题 更多 >
编程相关推荐