简体   繁体   English

导入错误 Python 3 与 tkinter 类

[英]Import Error Python 3 with tkinter classes

I know this is probably quite easy to solve but I dont know the answer.我知道这可能很容易解决,但我不知道答案。

I have the following folder structure in my python3 project:我的 python3 项目中有以下文件夹结构:

---UserInterface
------__init__.py
------MainApplication.py
------StartPage.py

(PS my __init__.py is empty) (PS 我的 __init__.py 是空的)

Now I want to add the StartPage to my MainApplication and I try the following import.现在我想将 StartPage 添加到我的 MainApplication 并尝试以下导入。

from . import StartPage

I am getting the following error: ImportError: cannot import name 'StartPage' from '__main__'.我收到以下错误:ImportError: cannot import name 'StartPage' from '__main__'。

Can anyone tell me where the problem with importing is?谁能告诉我导入的问题在哪里? (My main method is inside my MainApplication.py) (我的主要方法在我的 MainApplication.py 中)

did you just try import StartPage ?您刚刚尝试import StartPage吗? the error text says that there is no StartPage in main .错误文本说main中没有StartPage You run MainApplication and it gets the name main after launch.您运行MainApplication并在启动后获得名称main This means that an attempt is being made to import StartPage from the MainApplication .这意味着正在尝试从MainApplication StartPage But it's not there但它不存在

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM