2
votes

So i'm learning Kivy for a school project and i got an error when testing out Buttons. Here is my Code:

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.clock import Clock
from kivy.uix.button import Button


class übung(GridLayout):

    def lol(instance):
         label.disabled = False


    def __init__(self):
        super(übung, self).__init__
        self.cols = 2
        self.label = Label ("Ehrm ... lol")
        label.disabled = True
        self.btn1 = Button(text="Hello world 1")
        self.btn1.bind(on_press=lol)
        self.btn2 = Button(text="Hello world 2")
        self.btn2.bind(on_press=lol)

class App(App):
     def build(self):
        return übung()


if __name__ == "__main__":
    App().run()

The Error I'm getting is in the title(init takes 1 postitional argument but 2 were given). It is supposed to be two buttons and if you press one it say ehrm ... lol. As i said, it is just for testing purposes.

Thanks in Advance, me

1
What's the exact error? Where is the error happening? - Carcigenicate
It's already solved. I just didn't add the self.add_widget(self.(name)) - Banana

1 Answers

2
votes

You have several errors. The error you display is because you have to pass the argument (text) to the Label constructor by name:

self.label = Label (text="Ehrm ... lol")

Your code should look something like this:

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.button import Button


class übung(GridLayout):
    def __init__(self, **kwargs):
        super(übung, self).__init__(**kwargs)
        self.cols = 2
        self.label = Label(text = "Ehrm ... lol")
        self.label.disabled = True
        self.btn1 = Button(text="Hello world 1")
        self.btn1.bind(on_press=self.lol)
        self.btn2 = Button(text="Hello world 2")
        self.btn2.bind(on_press=self.lol)

        self.add_widget(self.label)
        self.add_widget(self.btn1)
        self.add_widget(self.btn2)

    def lol(self,  event):
        self.label.disabled = False

class App(App):
     def build(self):
        return übung()


if __name__ == "__main__":
    App().run()