在类内调用函数

2024-06-01 01:53:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我怎样才能像这样在类中调用函数呢?我试过了,但是我不能。。。想法是:我想更新de类中的另一个函数,而不是使用此代码,但没有成功:app=MyApp()app.build.last1版本.文本=时间.strftime(“%H:%M:%S\n”)

我是怎么做到的?你知道吗

(…)

class PL1_detect(Button):

    def update(self, dt):
                global ModoPisca
                global t
                global ModoPisca2
                global last2


                #ModoPisca=0
                def tpisca():
                    conta=0
                    global estado_PTT1
                    ##clock(self, dt)
                    app=MyApp()
                    app.build.last1.text=time.strftime("%H:%M:%S \n")
                   #(here the problem: HOW I CAN CALL FUNCTION OF CLASS 

我的应用程序(应用程序)????你知道吗

(…)

class MyApp(App):   


    def build(self):


                layout = FloatLayout(size=(800, 600))
        # Make the background gray:
        with layout.canvas.before:
            Color(.2,.2,.2,1)
            self.rect = Rectangle(size=(800,600), pos=layout.pos)


                wimg = Image(source='logo.png', pos=(0,180))

        last1=Label(text=(" "), pos=(-330, -110), font_size='17sp', bold=0)

        return layout

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

Tags: textposbuildselfappsizedefdt
2条回答

可以为该类创建对象 M=Myapp() M.build()将有助于调用该函数。你知道吗

在你的场景中试试这个

class A():
    def funct1(self):
        sample="hi"

class B():
    def func2(self):
        A.sample="hello"
        print A.sample

a=A()
a.funct1()
b=B()
b.func2()

输出: 你好

可以为该类创建对象 M=Myapp() M.build()将有助于调用该函数。你知道吗

在你的场景中试试这个

class A():
    def funct1(self):
        sample="hi"

class B():
    def func2(self):
        A.sample="hello"
        print A.sample

a=A()
a.funct1()
b=B()
b.func2()

输出: 你好

相关问题 更多 >