首页 > 解决方案 > 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()

标签: pythonkivy

解决方案


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.


推荐阅读