Reputation: 7
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).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) 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) File "kivy_event.pyx", line 245, in 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>
I am a beginner so I don't why this is showing up
Upvotes: 0
Views: 461
Reputation: 39082
I believe the problem is in the line:
self.calc = TextInput(Multiline = False)
the keyword should be multiline
(no capitals):
self.calc = TextInput(multiline = False)
Also,
self.sub.bind(in_press = self.press())
should be:
self.sub.bind(in_press = self.press)
without ()
.
Upvotes: 0