Search code examples
pythonkivy

kivy, do 2 def in class


what i want to do is run two defs but the second def is never executed.

In short, how can I execute the lines named 'print('sj')' in this code?

class Welcome(GridLayout):

    def __init__(self, **kwargs):
        super(Welcome, self).__init__(**kwargs)
        self.cols = 2
        self.add_widget(Label(text='[color=256bdb]Hoş[/color][b] geldin![/b]', font_size='31sp', halign="left", markup = True))

        
    def sj():
        print("sj")
        print("sj")
        print("sj")
        print("sj")
        print("sj")
        print("sj")
        print("sj")
        print("sj")
        print("sj")
        

###

class MyApp(App):

    def build(self):
        return Welcome()

###

if __name__ == '__main__':
    MyApp().run()

Solution

  • Good day. the sj() function has several potential issues with it. It's either out of scope (indented when it suppose to be near the edge) or ill defined as a method (missing self as in def sj(self):)

    Choose either solution and your program should work.