Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将参数发送到Kivy.app.on_启动函数_Python_Kivy - Fatal编程技术网

Python 将参数发送到Kivy.app.on_启动函数

Python 将参数发送到Kivy.app.on_启动函数,python,kivy,Python,Kivy,我有一些代码是这样的(MRE): 它回来了 AttributeError: 'NoneType' object has no attribute '*what I'm trying to access*' 玩了一会儿,我了解到问题在于我在分配任务时发送参数 MyApp.on_start = my_function(some arguments) 我一直在尝试多种解决方案,例如使用 setattr(MyApp, 'on_start', my_function(some arguments))

我有一些代码是这样的(MRE):

它回来了

 AttributeError: 'NoneType' object has no attribute '*what I'm trying to access*'
玩了一会儿,我了解到问题在于我在分配任务时发送参数

MyApp.on_start = my_function(some arguments)
我一直在尝试多种解决方案,例如使用

setattr(MyApp, 'on_start', my_function(some arguments))
分配给

MyApp.run(some arguments)
打电话,但没用。 我该怎么办


谢谢大家!

我认为您可以使用
部分
来完成此操作:

from functools import partial
from kivy.app import App


def my_function(*arguments):
    print('in my_function')
    for arg in arguments:
        print('\t', arg)

MyApp = App()
MyApp.on_start = partial(my_function, 'abba', 'dabba')
MyApp.run()

应用程序
类的
启动
功能设置为调用您的
我的
类如何

from kivy.app import App

class MyApp(App):
    def on_start(self):
        self.my_function('foo','bar')

    def my_function(self, *args):
        print(args)

MyApp().run()

张贴一个完整的例子。你为什么还要尝试设置一些外部函数的启动?除了有多个函数,在启动时调用哪个函数取决于运行应用程序之前的后端。我知道它不在MRE中,但我认为它不应该在那里,因为它与问题没有直接关系。难道你不能在启动时的
函数中有一些逻辑来告诉以后调用哪个函数吗?
from kivy.app import App

class MyApp(App):
    def on_start(self):
        self.my_function('foo','bar')

    def my_function(self, *args):
        print(args)

MyApp().run()