带有自定义函数的Python+Kivy接口

2024-09-30 06:28:28 发布

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

我正在尝试为我编写的脚本构建一个接口,该脚本根据用户提交的票证处理对用户的自动回复。你知道吗

当我试图将我的函数转换为在应用程序中使用时遇到错误。你知道吗

无法正常工作的代码如下所示

class MyApp(App):

    o = win32.gencache.EnsureDispatch("Outlook.Application").GetNamespace("MAPI")
    ol = win32.Dispatch('outlook.application')

    def sf(self):

        folders = self.o.Folders
        tardir = self.root.ids.label.main_inbox

        for folder in folders:
            if folder.Name == tardir:
                return folder
            folderMatch = self.sf()
            if folderMatch:
                return folderMatch

我得到以下错误:

Traceback (most recent call last):
   File "_ctypes/callbacks.c", line 234, in 'calling callback function'
   File "C:\Python\Python36-32\lib\site-packages\kivy\input\providers\wm_touch.py", line 127, in _touch_wndProc
     lParam)
 ctypes.ArgumentError: argument 3: <class 'RecursionError'>: maximum recursion depth exceeded while calling a Python object

这个函数来自我的原始代码,预接口如下

def sf(folders, tardir):    
    for folder in folders:  # if `folder` follows python convention, it should be iterable.
        if folder.Name == tardir: # is it the correct folder?
            return folder 
        folderMatch = sf(folder.Folders, tardir)  # recurse into child folders
        if folderMatch: 
            # return result from recursive call of sf() if successful
            return folderMatch

任何帮助都将不胜感激。。。我迷路了。你知道吗

****建议答案后编辑****

我实现了这个更改,当尝试使用这个函数时,我得到一个错误

 Traceback (most recent call last):
   File "C:\Python\Python36\emailBotInterface.py", line 175, in <module>
     MyApp().run()
   File "C:\Python\Python36\lib\site-packages\kivy\app.py", line 802, in run
     root = self.build()
   File "C:\Python\Python36\emailBotInterface.py", line 108, in build
     label.unhandled_requests = self.config.get(get_folderMatch())
 NameError: name 'get_folderMatch' is not defined

我尝试以这种方式使用函数:

def build(self):
        """
        Build and return the root widget.
        """

        # The line below is optional. You could leave it out or use one of the
        # standard options, such as SettingsWithSidebar, SettingsWithSpinner
        # etc.
        self.settings_cls = MySettingsWithTabbedPanel

        # We apply the saved configuration settings or the defaults
        root = Builder.load_string(kv)
        label = root.ids.label
        label.main_inbox = self.config.get('Mail Config', 'main_inbox')
        label.comments_folder = self.config.get('Mail Config', 'comments_folder')
        label.excess_folder = self.config.get('Mail Config', 'excess_folder')
        label.search_string = self.config.get('Mail Config', 'search_string')
        label.unhandled_requests = self.config.get(MyApp.get_folderMatch())

        return root

Tags: inselfconfiggetreturniflineroot
1条回答
网友
1楼 · 发布于 2024-09-30 06:28:28

以下代码由eyllanesc提供,有助于发现问题。我没有尝试使用self.config.get(get_folderMatch()),而是意识到我不需要显示这个配置。所以,我刚刚为label创建了属性,并像这样赋值,label.unhandled_requests = self.get_folderMatch(label.main_inbox),一切都很好。你知道吗

@staticmethod
def sf(folders, tardir):    
    for folder in folders:  # if `folder` follows python convention, it should be iterable.
        if folder.Name == tardir: # is it the correct folder?
            return folder 
        folderMatch = MyApp.sf(folder.Folders, tardir)  # recurse into child folders
        if folderMatch: 
            # return result from recursive call of sf() if successful
            return folderMatch

def get_folderMatch(self, tardir):
    folderMatch = MyApp.sf(MyApp.o.Folders, self.root.ids.label.main_inbox)
    return folderMatch

相关问题 更多 >

    热门问题