[英]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.