繁体   English   中英

我用 Python 做了一个简单的计算器 kivy 程序。 但是出现了一个arror,我不明白它想说什么

[英]I made a simple calculator kivy program in Python. But an arror is showing up and i don't understand what it's trying to say

这是代码 -

import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput



class mygl(GridLayout):
    def __init__(self, **kwargs):
        super(mygl, self).__init__(**kwargs)
        self.cols = 2
        self.add_widget(Label(text = "input calculation :", font_size = 40))
        self.calc = TextInput(Multiline = False)
        self.add_widget(self.calc)
        self.sub = Button(text = "Submit")
        self.add_widget(self.sub)
        self.sub.bind(in_press = self.press())

    def press(self, instance):
        a = self.calc.text
        b = a.split(" ")
        if b[1] == "+":
            self.add_widget(Label(text = b[0] + b[2]))
        elif b[1] == "-":
            self.add_widget(Label(text = b[0] - b[2]))
        elif b[1] == "X":
            self.add_widget(Label(text = b[0] * b[2]))


class calculator(App):
    def build(self):
        return mygl()

calculator().run()

这是错误 -

Traceback(最近一次调用最后一次):文件“c:\Users\Vinay Mohnot\OneDrive\Desktop\Aditya Coding VS code\no.py”,第 37 行,在calculator().run() 文件“C:\Users\ Vinay Mohnot\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\app.py”,第 949 行,运行 self._run_prepare() 文件“C:\Users\Vinay Mohnot\AppData\Local\ Programs\Python\Python39\lib\site-packages\kivy\app.py”,第 919 行,在 _run_prepare root = self.build() 文件“c:\Users\Vinay Mohnot\OneDrive\Desktop\Aditya Coding VS code\ no.py”,第 35 行,在构建中返回 mygl() 文件“c:\Users\Vinay Mohnot\OneDrive\Desktop\Aditya Coding VS code\no.py”,第 16 行,在init self.calc = TextInput(Multiline = False)文件“C:\Users\Vinay Mohnot\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\textinput.py”,第 528 行,在init super(TextInput, self) 中。 init (**kwargs) 文件“C:\Users\Vinay Mohnot\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\behaviors\focus.py”,第 367 行,在init super(焦点行为,自我)。 init (**kwargs) 文件“C:\Users\Vinay Mohnot\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\widget.py”,第 350 行,在init super(Widget,自己)。 init (**kwargs) 文件“kivy_event.pyx”,第 245 行,在 kivy._event.EventDispatcher 中。 初始化类型错误:对象。 init () 只接受一个参数(要初始化的实例) PS C:\Users\Vinay Mohnot\OneDrive\Desktop\Aditya Coding VS code>

我是初学者,所以我不知道为什么会出现

我相信问题出在:

self.calc = TextInput(Multiline = False)

关键字应该是multiline (没有大写):

self.calc = TextInput(multiline = False)

还,

self.sub.bind(in_press = self.press())

应该:

self.sub.bind(in_press = self.press)

没有()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM