简体   繁体   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

This is the code -这是代码 -

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()

this is the error -这是错误 -

Traceback (most recent call last): File "c:\Users\Vinay Mohnot\OneDrive\Desktop\Aditya Coding VS code\no.py", line 37, in calculator().run() File "C:\Users\Vinay Mohnot\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\app.py", line 949, in run self._run_prepare() File "C:\Users\Vinay Mohnot\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\app.py", line 919, in _run_prepare root = self.build() File "c:\Users\Vinay Mohnot\OneDrive\Desktop\Aditya Coding VS code\no.py", line 35, in build return mygl() File "c:\Users\Vinay Mohnot\OneDrive\Desktop\Aditya Coding VS code\no.py", line 16, in init self.calc = TextInput(Multiline = False) File "C:\Users\Vinay Mohnot\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\textinput.py", line 528, in init super(TextInput, self). 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) File "C:\Users\Vinay Mohnot\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\behaviors\focus.py", line 367, in init super(FocusBehavior, 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) File "C:\Users\Vinay Mohnot\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\widget.py", line 350, in init super(Widget, self). init (**kwargs) 文件“C:\Users\Vinay Mohnot\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\widget.py”,第 350 行,在init super(Widget,自己)。 init (**kwargs) File "kivy_event.pyx", line 245, in kivy._event.EventDispatcher. init (**kwargs) 文件“kivy_event.pyx”,第 245 行,在 kivy._event.EventDispatcher 中。 init TypeError: object.初始化类型错误:对象。 init () takes exactly one argument (the instance to initialize) PS C:\Users\Vinay Mohnot\OneDrive\Desktop\Aditya Coding VS code> init () 只接受一个参数(要初始化的实例) PS C:\Users\Vinay Mohnot\OneDrive\Desktop\Aditya Coding VS code>

I am a beginner so I don't why this is showing up我是初学者,所以我不知道为什么会出现

I believe the problem is in the line:我相信问题出在:

self.calc = TextInput(Multiline = False)

the keyword should be multiline (no capitals):关键字应该是multiline (没有大写):

self.calc = TextInput(multiline = False)

Also,还,

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

should be:应该:

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

without () .没有()

暂无
暂无

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

相关问题 语音重演程序出现问题,因为该程序不能理解我的意思,这是什么问题? - Having issues with speech regonition program as the program isn't picking up what I say, what's the issue? Python:我不明白这个生成器发生了什么 - Python: I don't understand what's happening with this generator 我正在尝试用 python 制作一个 bmi 计算器,但我不知道我做错了什么 - I'm trying to make a bmi calculator in python and I don't know what I'm doing wrong 试图用python继承来理解这里简单的东西的根本区别,而我什至不知道该怎么称呼它 - Trying to understand the fundamental difference on something simple here with python inheritance vs i don't even know what to call this ';'有什么用 在python中。 我没有看到解释此问题的文档 - what is the use of ';' in python. I don't see a document that explains this 我不理解 Python 中的负边界切片。 这应该如何工作? - I don't understand slicing with negative bounds in Python. How is this supposed to work? 尝试运行我在 python 中制作的简单加法计算器时出现 int 错误 - I get an int error when trying to run a simple addition calculator i made in python 我不明白为什么我的 python 代码显示警告? - I don't understand why my python code is showing warning? 我不明白为什么我不能让 python 中的 readline function 在这个程序中工作。 我究竟做错了什么? - I don't understand why i can't get readline function in python to work in this program. What am I doing wrong? 我正在尝试使用记事本++启动一个简单的计算器程序,我做错了什么? - I am trying to start a simple calculator program using notepad++, what am I doing wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM