<p>为了解决这个问题,我做了以下工作。使用<a href="https://docs.beeware.org/en/latest/tutorial/tutorial-2.html" rel="nofollow noreferrer">Beeware Tutorial 2</a>源代码的示例位于<a href="https://github.com/zasoliton/beeware_custom_lib" rel="nofollow noreferrer">Github</a></p>
<pre><code>.
├── __init__.py
├── __main__.py
├── app.py
├── mylib < - # my lib.
│ ├── __init__.py
│ └── testlib.py
└── resources
├── __init__.py
├── beewarecustomlibexample.icns
├── beewarecustomlibexample.ico
└── beewarecustomlibexample.png
2 directories, 9 files
</code></pre>
<p>{<cd1>}</p>
<pre><code>def test(text: str) -> str:
return f"Hello: {text}"
</code></pre>
<p>在<code>app.py</code>中:</p>
<pre><code>import toga
from toga.style import Pack
from toga.style.pack import COLUMN, ROW
from beewarecustomlibexample.mylib.testlib import test # Import custom lib
class BeewareCustomLibExample(toga.App):
def startup(self):
...
def say_hello(self, widget):
# Calling my test method
result = test(self.name_input.value)
self.main_window.info_dialog("Test Dialog", result)
def main():
return BeewareCustomLibExample()
</code></pre>
<p>以上就是我如何让它工作的。我已经在MacOS上构建了它,运行良好</p>